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
|
# $Header: /home/orodruin/h/bair/phelps/spine/tkman/RCS/tkman.tcl,v 2.147 1998/02/12 00:16:44 phelps Exp phelps $
#
# Bird? Plane? TkMan! (TkPerson?)
#
# by Tom Phelps (phelps@ACM.org)
# March 24-25, 1993
#
# Copyright (c) 1993-1997 Thomas A. Phelps
#
# add more anchors to help pages and add context help?
# maybe link to clicking on label in Preferences...
# put short UNIX names in preferences(?) => belongs in Makefile, where it is now
# in addition to history list, back and forward buttons (Robert Withrow)
# if run by tclsh, null out Tk commands, assume -rebuildandquit?
# nah, quick enough to build database that don't need to relegate this to an nighttime cron job
# add assertions.
# optimized Makefile target zaps assertions, debugging
# if empty search string set to man page name (Ian Darwin)
# split screen with slider for names and page contents?
# option for TkMan autoraise or leave that to window manager?
# should rewrite Preferences so that entries are specified descriptively
# and a general interpretation proc builds the gui -- like exmh does
# embed Preferences widgets into help page?
# hide inside collapsed and instantiate widgets on demand?
###
### proc's (only--no variables, proc calls)
###
set manx(startuptime) [clock seconds]
wm withdraw .; update idletasks
# could check for existing TkMan, if found raise its window and kill self,
# but person may want to run on different OSes from same screen
#--------------------------------------------------
#
# Shortcuts
#
#--------------------------------------------------
proc manShortcuts {w cmd} {
global man manx short
# set me $manx(name$w)
set me $manx(typein$w)
# if {![string match "<*" $me]} { append me ".$manx(cursect$w)" }
#puts "$manx(man$w) => $manx(name$w).$manx(cursect$w)"
set modeok [lmatch {man txt texi} $manx(mode$w)]
if {$cmd!="init" && (!$modeok || $manx(man$w)=="")} return
set present [expr [lsearch -exact $manx(shortcuts) $me]!=-1]
if {$cmd=="add" && !$present} {lappend manx(shortcuts) $me; set short($me) [clock seconds]} \
elseif {$cmd=="sub" && $present} {set manx(shortcuts) [lfilter $me $manx(shortcuts)]}
# update menu
set m .shortcuts
$m delete 0 last
set len [llength $manx(shortcuts)]
# store list by time added, sort on demand
set list $manx(shortcuts)
if $man(shortcuts-sort) { set list [lsort $list] }
if {$len} {
foreach i $list {
# if {![regexp {^[<|]} $i]} {
# usual man page
# if {[lsearch $manx(mandot) $i]>-1} {set name $i} {set name [file rootname $i]}
# } else {set name $i}
$m add command -label $i -command "incr stat(man-shortcut); manShowMan [list $i] {} \$curwin"
}
}
foreach win [lmatches ".man*" [winfo children .]] {
manShortcutsStatus $win
}
manMenuFit $m
}
proc manShortcutsStatus {w} {
global man manx
global bmb
# set me $manx(name$w)
set me $manx(typein$w)
# if {![string match "<*" $me]} { append me ".$manx(cursect$w)" }
set modeok [lmatch {man texi txt} $manx(mode$w)]
set present [expr [lsearch -exact $manx(shortcuts) $me]!=-1]
set b $w.stoggle
if {$modeok} {
if $present {set cmd "sub"; set text "-"
} else {set cmd "add"; set text "+"
}
$b configure -text $text; set bmb($b) "incr stat(page-shortcut-$cmd); manShortcuts $w $cmd"
} else {$b configure -text "x"; set bmb($b) ""}
}
# compensate for Tk's nonalphnum-bounded wordstart and wordend
# should have companions to word{start,end} that are bounded by whitespace, not nonalpha
# (in this case analysis too complex for an extended wordstart)
proc manHotSpot {cmd t xy} {
global man manx curwin
set manchars {[ a-z0-9_.~/$+()-:<]}
set manx(hotman$t) ""
# click again in hot spot without time considerations
# if {!catch{$t index hot.first} && [$t compare hot.first <= $xy] && [$t compare $xy >= hot.last]} {
# set cmd get
# }
# act on command
if {$cmd=="clear"} {
$t tag remove hot 1.0 end
return
}
scan [$t index $xy] "%d.%d" line char
scan [$t index "$line.$char lineend"] "%d.%d" bozo lineend
# else $cmd=="show"
$t tag remove hot 1.0 end
# command line options trump
# FLAT, RAISED, SUNKEN, GROOVE, SOLID, or RIDGE
if {0 && $manx(mode$curwin)=="man" && ([$t get [set cmdstart "$xy wordstart-1c"]]=="-" || [$t get [set cmdstart "$xy wordstart"]]=="-")} {
set skipe "\[]\[\t .,;:\{\}?\]"
scan [$t index $cmdstart] "%d.%d" line char
for {set c0 $char} {$c0>0 && ![regexp $skipe [$t get $line.$c0]]} {incr c0 -1} {}
incr c0; # went one too far
scan [$t index "$xy wordend"] "%d.%d" line char
for {set cn $char} {$cn<$lineend && ![regexp $skipe [$t get $line.$cn]]} {incr cn} {}
if {[lsearch [$t tag names $line.$c0] "cmd"]==-1} {set toggle "add"} {set toggle "remove"}
$t tag $toggle cmd $line.$c0 $line.$cn
selection own $curwin.man
return
}
### 8.0: possible to take advantage of tcl_endOfWord?
# special cases when clicking on parentheses
set c [$t get $line.$char]
if {$c=="("} {
if {$char>0 && [$t get $line.$char-1c]!=" "} {incr char -1} {incr char}
} elseif {$c==")"} {
if {$char>0} {incr char -1}
}
set lparen 0; set rparen 0
# single space between name and parenthesized volume ok (found mainly in apropos but some page too)
set fspace 0
# gobble characters forwards
for {set cn $char} {$cn<=$lineend && [regexp -nocase $manchars [set c [$t get $line.$cn]]]} {incr cn} {
if {$c=="("} {
if {!$lparen} {set lparen $cn} else break
} elseif {$c==")"} {
if {!$rparen} {set rparen $cn; incr cn}
break
} elseif {$c==":" && ([$t get $line.$cn+1c]==" " || [$t get $line.$cn-1c]==" ")} {
break
} elseif {$c==" "} {
if {!$lparen && !$fspace && $cn<$lineend && [$t get $line.$cn+1c]=="("} {set fspace 1} else break
}
}
incr cn -1
# gobble characters backwards
for {set c0 $char} {$c0>=0 && [regexp -nocase $manchars [set c [$t get $line.$c0]]]} {incr c0 -1} {
if {$c=="("} {
if {!$lparen} {set lparen $c0} else break
} elseif {$c==")"} {
break
} elseif {$c==":" && ([$t get $line.$c0+1c]==" " || [$t get $line.$c0-1c]==" ")} {
break
} elseif {$c==" "} {
if {$lparen==[expr $c0+1] && !$fspace} {set fspace 1} else break
}
}
incr c0
# adjust if parentheses unbalanced
if {!$lparen^!$rparen} {
if {$lparen} {
if {$char>$lparen} {set c0 [expr $lparen+1]} {set cn [expr $lparen-1]}
set lparen 0
} else {
# trim off right paren
incr cn -1
}
# check for valid section number
} elseif {$lparen && [lsearch $man(manList) [$t get $line.$lparen+1c]]==-1} {
if {$char>$lparen} {set c0 [expr $lparen+1]} {set cn [expr $lparen-1]}
set lparen 0
# nothing between parentheses
} elseif {$lparen==[expr $rparen-1] && $lparen>0} {
set cn [expr $lparen-1]
# if have good parens, can't start with a "/"
} elseif {$lparen && $rparen && [$t get $line.$c0]=="/"} {
incr c0
}
# clean up sides
while {$c0>0 && [lsearch {" "} [$t get $line.$c0]]>=0} {incr c0}
while {$cn>$c0 && [lsearch {. - , " "} [$t get $line.$cn]]>=0} {incr cn -1}
$t tag add hot $line.$c0 $line.$cn+1c
set hyper [string trim [$t get $line.$c0 $line.$cn+1c]]
# if clicked on absolute name, it's probably not a man page -- it is if I generated it
#if [string match "/*" $hyper] {set hyper "<$hyper"}
set manx(hotman$t) $hyper
}
proc manInstantiate {} {
global stat manx
incr stat(instantiation)
incr manx(uid)
incr manx(outcnt)
set w [TkMan]
manOutput
return $w
}
proc manOutput {} {
global manx
set wins [lmatches ".man*" [winfo children .]]
# make list of output choices
set titleList {}
foreach i [lsort -dictionary $wins] {
set title "#[string range $i 4 end]"
# special case for main window
if {$title=="#"} {append title 1}
lappend titleList $title $i
}
# update list on each instantiation
set wincnt 0
foreach w $wins {
set mb $w.output; set m $mb.m
$m delete 0 last
set mcnt 0
foreach {label val} $titleList {
set newlabel [expr {$wincnt==$mcnt?"Output":"=>$label"}]
$m add radiobutton -label $label -variable manx(out$w) -value $val \
-command "$mb configure -text $newlabel"
incr mcnt
}
manMenuFit $m
# if pointing to a zapped instance, reset to self
if ![winfo exists $manx(out$w)] {set manx(out$w) $w; $w.output configure -text "Output"}
incr wincnt
}
# if multiple choices, show menu
if {$manx(outcnt)==1} {
pack forget .man.output
} else {
foreach w $wins {pack $w.output -before $w.occ -padx 2 -side left -expand yes}
}
}
#--------------------------------------------------
#
# file completion
#
#--------------------------------------------------
proc manFilecomplete {w} {
global manx
set t $w.show; set wi $w.info
set line $manx(typein$w)
set file [string trim [llast $line] "<"]
set posn [string last $file $line]
set ll [llength [set fc [filecomplete $file]]]
#puts stdout "$line, $file, $posn, $fc"
# check for no matches or more than one match
if {!$ll} {
manWinstderr $w "no matches"
return
} elseif {$ll>=2} {
set matches {}; foreach i $fc {lappend matches [file tail $i]}
if {[string length $matches]<50} {
manWinstderr $w [lrest $matches]
} else {
manTextOpen $w
$t insert end [lrest $matches]
manTextClose $w
}
set fc [lfirst $fc]
}
# show new file name
set manx(typein$w) [string range $line 0 [expr $posn-1]]$fc
$w.mantypein icursor end
$w.mantypein xview moveto 1
}
#--------------------------------------------------
#
# manNewMode -- collect mode change inits in single place
# types of modes: section, man, txt, apropos, glimpse, help
#
#--------------------------------------------------
proc manNewMode {w mode {n {""}}} {
global man manx stat
$w.c delete all
set t $w.show
$t tag add area 1.0; $t tag configure area -elide 0
# save old highlights --> done continuously
# manHighlights $w
$w.high configure -foreground $man(buttfg) -background $man(buttbg) -font gui
# save old yview
if {[$t index @0,0]==1.0 || [catch {if {[$t index @0,0]!=1.0} {set manx(yview,$manx(hv$w)) [$t index $manx(cursect$t)]}}]} {set manx(yview,$manx(hv$w)) [$t index @0,0]}
set manx(oldmode$w) $manx(mode$w)
set manx(mode$w) $mode
set manx(manfull$w) ""
set manx(catfull$w) ""
set manx(man$w) ""
set manx(name$w) ""
set manx(num$w) ""
set manx(tryoutline$w) 0
# don't have to explicitly remove tags: done when delete all text "underneath"
# reset searching
# set manx(search,string$w) ""
set manx(search,oldstring$w) ""
$w.search.cnt configure -text ""
searchboxKeyNav "" Escape 0 $t $w.info 0
# if {$mode=="section"} {searchboxKeyNav C s 0 $t "" 1}
after 5 selection clear $t
# set sbx(lastkeys$w) ""
set manx(vect) 1
set manx(try) 0
set m $w.sections.m; eval destroy [winfo children $m]; $m delete 0 last
## $w.links.m delete 0 last
# removing tag doesn't fire a Leave event
$t configure -cursor left_ptr
# disable various ui buttons for different types
# (paths, volumes, shortcuts, history always available)
#
# man help txt info texi section apropos glimpse
# yview x x x x x ?
# sections x x x x
# highlights x x x
# links x x
# shortcuts +/- x x x
# print x
set high(0) disabled; set high(1) normal
set h $high([lmatch {man help info texi rfc} $mode]); $w.sections configure -state $h
#tcl java
set h $high([lmatch {man txt rfc help} $mode])
#tcl java
# $w.high state controlled by highlighting code
foreach i {high} {$w.$i configure -state $h}
# if {![lmatch {man txt help} $mode]} {
## foreach i {high hsub} {$w.$i configure -state disabled}
# }
## set h $high([lmatch {man help} $mode]); $w.links configure -state $h
# if {![lmatch {man txt rfc texi} $mode]} {
#tcl java
# foreach i {stoggle} {$w.$i configure -state disabled}
#sadd ssub
# }
set h $high([lmatch man $mode]); .occ entryconfigure "Kill Trees" -state $h
manHyper $w $n
}
# set mouse clicks for hyperlinking
proc manHyper {w {n ""}} {
global man manx
set t $w.show
# clear old settings
foreach i {"Double-" ""} {
foreach j {"" "Alt-" "Shift-"} {
$t tag bind hyper <${j}${i}ButtonRelease-1> "format nothing"
}
}
if {$man(hyperclick)=="double"} {set mod "Double-" } { set mod "" }
$t tag bind hyper <ButtonRelease-1> "
if {\$manx(hotman$t)!={}} { set manx(typein$w) \$manx(hotman$t) }
"
$t tag bind hyper <${mod}ButtonRelease-1> "+
if {\$manx(hotman$t)!={}} { incr stat(man-hyper); manShowMan \$manx(hotman$t) $n \$manx(out$w) }
"
$t tag bind hyper <Shift-${mod}ButtonRelease-1> "
if {\$manx(hotman$t)!={}} { incr stat(man-hyper); set manx(shift) 1; manShowMan \$manx(hotman$t) $n \$manx(out$w) }
"
$t tag bind hyper <Alt-${mod}ButtonRelease-1> "
if {\$manx(hotman$t)!={}} { set manx(typein$w) \$manx(hotman$t); manShowMan <\$manx(hotman$t) \$manx(out$w) }
"
# (<Button-1> and <Button1-Motion> don't change)
}
#--------------------------------------------------
#
# manXXX - miscellaneous medium-level commands
#
#--------------------------------------------------
# just jab some text into the widget regardless of state
proc manTextPlug {t posn args} {
set state [$t cget -state]
$t configure -state normal
eval $t insert $posn $args
$t configure -state $state
}
proc manTextOpen {w} {
global man manx
#raise $w
cursorBusy
set t $w.show
$t configure -state normal
$t delete 1.0 end
# delete all marks and tags
set manx(sectposns$w) ""
set manx(cursect$t) js1
foreach i [$t mark names] {if {$i!="insert"&&$i!="current"} {$t mark unset $i}}
foreach i [$t tag names] {if {[string match "js\[0-9\]*" $i]||[string match "areajs\[0-9\]*" $i]} {$t tag delete $i}}
}
proc manTextClose {w} {
set t $w.show
# zap final newline so last line is flush with bottom
if {[$t get "end -2c"]=="\n"} {$t delete "end -2c"}
$t tag add hyper 1.0 end
if {[lsearch [$t mark names] "endcontent"]==-1} {$t insert end " "; $t mark set endcontent end-1c}
$t configure -state disabled
cursorUnset
$t mark set xmark 1.0
# if {[lsearch [$t mark names] "endcontent"]==-1} {$t mark set endcontent end}
}
proc manResetEnv {} {
global env man manx mani
set manpath {}
foreach i $manx(paths) {if {$man($i)} {append manpath :$i}}
set env(MANPATH) [string range $manpath 1 end]
# also updates contents of volume listings
foreach i $manx(manList) {
if {[lsearch $manx(specialvols) $i]==-1 || $i=="all"} {set mani($i,form) ""}
}
}
proc manSetSect {w n} {
global manx mani
set manx(cursect$w) *
# passed full pathname, search for volume
if [regexp {^/} $n] {
set dir [file dirname $n]
# try to find (possibly remapped) volume
foreach vol $mani(manList) {
if [lsearch -exact $mani($vol,dirs) $dir]!=-1 {
set manx(cursect$w) $vol
# set f [lsearch -exact $mani(manList) $vol]
return $vol
}
}
# else if has .<char>, take that
if {[regexp {\.(.)[^/\.]*$} $n all letter]} {
set manx(cursect$w) $letter
return $letter
}
# passed alphanum, use if valid
} elseif {[set f [lsearch $manx(manList) $n]]!=-1} {
set manx(cursect$w) $n
}
# $w.volnow configure -text "([lindex $manx(manList) $f]) [lindex $manx(manTitleList) $f]"
#$w.volnow configure -text ""
return $n
}
# put entire pulldown menu on screen, using progressively smaller fonts as necessary
proc manMenuFit {m} {
global man manx
if {[winfo class $m]!="Menu"} {puts stderr "$m not of Menu class"; exit 1}
if {[$m index last]=="none"} return
set sh [winfo screenheight $m]
# starting with current gui font size, pick smaller font as needed
# until all entries fit on screen or out of smaller fonts
set ok 0
for {set i [expr [lsearch $manx(sizes) $man(gui-points)]+1]} {$i>=0} {incr i -1} {
set p [lindex $manx(pts) $i]
set f [spec2font $man(gui-family) $man(gui-style) $p]
$m configure -font $f; update idletasks
set mh [winfo reqheight $m]
#DEBUG {puts stderr "manMenuFit $m: $f, $mh, $sh"}
if {$mh<$sh} {set ok 1; break}
}
# if menu still too big for screen, clip entries from bottom until it is
if {!$ok} {
set ctr 0
# kind of heavyweight but don't need to do this often
while {[winfo reqheight $m]>=$sh} {
$m delete last; incr ctr; update idletasks
}
# make space for "too many" at bottom
$m delete last; incr ctr
$m add command -label "($ctr too many to show)" -state disabled
}
}
#--------------------------------------------------
#
# manInit -- determine which sections exist,
#
#--------------------------------------------------
proc manInit {} {
global man manx mani
if {$manx(init)} return
manReadSects
# MANPATH may have shifted during startup
manResetEnv
set manx(init) 1
}
proc manSortByTail {a b} {
return [string compare [string tolower [file tail $a]] [string tolower [file tail $b]]]
}
# man page, Texinfo, Help
proc manShowManFoundSetText {w t key} {
global man manx
set alljs [lmatches "js*" [$t mark names]]
# set manx(sectposns$w) [lsort -command "bytextposn $t " $alljs]
set manx(sectposns$w) [lsort -dictionary $alljs]
set manx(nextposns$w) [concat [lrange $manx(sectposns$w) 1 end] endcontent]
set manx(cursect$t) [lfirst $manx(sectposns$w)]
# compute number of levels to show in Sections
for {set i 0} {$i<10} {incr i} {set last($i) ""; set clevel($i) 0}
foreach i $manx(sectposns$w) {incr clevel([regsub -all {\.} $i {\.} junk])}
set showlevel 0
set scnt $clevel(0)
for {set i 1} {$i<10} {incr i} {
incr scnt $clevel($i)
if {$scnt>50} break
incr showlevel
}
# fix up sections: remove hyper tag and reformat short sections -- always
# if short enough and no subsections, de-section-ify it. don't see diffs, though
# count lines in each section (not shown for short sections)
set manx(sectname$t) {}
$t configure -state normal
foreach now $manx(sectposns$w) next $manx(nextposns$w) {
set manx(lcnt$now) [set manx(lcnt0$now) [expr int([$t index $next])-int([$t index $now])-1]]
for {set sup $now} {[regexp $manx(supregexp) $sup all supnum]} {set sup "js$supnum"} {
catch {incr manx(lcntjs$supnum) [expr $manx(lcnt$now)+1]}
}
$t tag remove hyper $now "$now lineend"
lappend manx(sectname$t) [$t get $now "$now lineend"]
set secttxt [$t get "$now linestart" "$now lineend"]
# set fNAME [expr {[string tolower $secttxt]=="name"}]
set fNAME [expr {$secttxt=="Name"}]
set eol [$t index "$now lineend"]
set skip($now) 0
# crunch short man sections, unless man(outline) off
set ss "$now linestart+1l"; set se "$now linestart+1l+$manx(lcnt$now)l"
if {$manx(mode$w)=="man" && $man(outline)!="off" && $manx(lcnt$now)<=5 && [lsearch -glob $manx(sectposns$w) $now.*]==-1} {
# quick feasiblity check
if {[$t compare "$ss+[expr $manx(screencols)*2]c" > $se]} {
set utxt [$t get $ss $se]; regsub -all " +" $utxt "" txt; set txtlen [string length $txt]
# if {$txtlen<60 || ($txtlen<80 && $fNAME)} {
# if {$txtlen<$man(columns)-10 || ($txtlen<$man(columns)*1.1 && $fNAME)} {
if {$txtlen<$manx(screencols) || ($txtlen<$manx(screencols)*1.1 && $fNAME)} {
set skip($now) 1
set manx(lcnt$now) [set manx(lcnt0$now) 1]
# append lines onto header, replacing with \n
# have to zap text in buffer rather than insert new text so as to preserve tags
$t insert "$now lineend" " "
# $t insert "$now lineend" " " {} $txt [expr {$fNAME?"sc":""}]
for {scan [$t index $se-1l] "%d" i} {[$t compare $i.0 > $now]} {incr i -1} {
while {[regexp "\[ \t\]" [$t get $i.0]]} {$t delete $i.0}
# RosettaMan strips trailing spaces
# make internals elided but keep \n's around for diff line numbers
$t insert $i.0 " "; $t delete $i.0-1c; $t insert $i.0 "\n" elide
}
# strip out multiple spaces
foreach {junk s} [$t tag nextrange h2 1.0] {}; append s "+3c"
while {[set x [$t search " " $s 2.0]]!=""} {$t delete $x}
# set zapend [expr int([$t index $se])]
# for {set i [expr int([$t index $ss])]} {$i<$zapend} {incr i} {$t delete $i.0 "$i.0 lineend"}
# since accept more characters to put NAME on single line, make them small
if {$fNAME} {$t tag add sc $eol "$now lineend"}
}
}
}
}
$t configure -state disabled
set manx(tryoutline$w) [expr {$manx(mode$w)=="texi" || ($man(outline)!="off"
# exceptions: help page, full page fits on screen
&& $manx(manfull$w)!="_help" && [$t bbox endcontent]=="")}]
### after reading in text, build sections menu, count lines, show highlights
# highlights
# if {$manx(catfull$w)!=""} {set manx(hv$w) $manx(catfull$w)} {set manx(hv$w) $manx(manfull$w)}
# always key highlights to name of source
set manx(hv$w) $key
# make sections menu
set m [set mb $w.sections].m
if {$manx(tryoutline$w)} {
$m add command -label "Expand next/scroll" -accelerator "Return" -command "manDownSmart $w $t"
# people can figure this out without help
$m add command -label "Toggle current" -accelerator "Button 1 on header" -command "manOutline $t -1 \$manx(cursect$t)"
$m add command -label "Current + hierarchy" -accelerator "Shift-Button 1 on header" -command "manOutline $t -1 \$manx(cursect$t) 1"
$m add command -label "Collapse current" -accelerator "Button 3 anywhere" -command "manOutline $t 1 \$manx(cursect$t)"
$m add command -label "Collapse all" -accelerator "Double-Button 3" -command "manOutline $t 1 * 1; if {\$manx(mode$w)==\"man\"} {notemarks $w $t}"
$m add separator
}
foreach now $manx(sectposns$w) txt $manx(sectname$t) {
set level [regsub -all {\.} $now {\.} junk]
set pfx ""; for {set j 0} {$j<$level} {incr j} {append pfx " "}
#puts "level $level: $txt"
#if {![regexp {[a-z]} $txt] && [string length $txt]>3} { set txt [string tolower $txt] } -- casified by RosettaMan
# expand/collapse section and subsections by clicking on title
if {$manx(tryoutline$w)} {
$t tag add outline "$now linestart" "$now lineend"
# set lmar [expr 0.5*$level]c; $t tag configure area$now -lmargin1 $lmar -lmargin2 $lmar
# $t configure -state normal; $t insert "$now lineend" [$t get $now+1l "$now+1l lineend"] sc
}
# at start of new entity at that level, close up everything at that level and below (== higher #)
for {set j 9} {$j>=$level} {incr j -1} {
if {$last($j)!=""} {
# insert a newline after group at same level
# $t insert $now "\n"
$t tag add area$last($j) "$last($j) lineend" "$now linestart"
}
set last($j) ""
}
set last($level) $now
if {$level<=$showlevel} {
$m add command -label "$pfx$txt" -command "incr stat(page-section); manOutlineYview $t $now"
}
}
# may have stuffed more text into top
# (also have to special case 1.0 in manOutlineYview)
catch {$m entryconfigure [expr [$m index last]-[llength $manx(sectname$t)]+1] -command "incr stat(page-section); $t see 1.0"}
for {set j 9} {$j>=0} {incr j -1} {
if {$last($j)!=""} {$t tag add area$last($j) "$last($j) lineend" "endcontent"}
}
# number of lines within each section (# subsections in Texinfo)
if $manx(tryoutline$w) {
# if {$manx(mode$w)!="texi"} {
#}
$t configure -state normal
# collapse/expand and report line count
# set firstsect 1
foreach now $manx(sectposns$w) secttxt $manx(sectname$t) {
if {$skip($now)} {
foreach tag [list area$now outline] {$t tag remove $tag $now "$now lineend"}
# $t tag configure area$now -elide 0
continue
}
# set secttxt [$t get "$now linestart" "$now lineend"]
set lcnt $manx(lcnt$now)
set effcnt $lcnt; if {$man(columns)>2*$manx(screencols)} {set effcnt [expr int(2.5*$effcnt)]}
append secttxt $effcnt
set closed 1; if {$manx(mode$w)=="man" && ($man(outline)=="allexp" || ([string match "allbut*" $man(outline)] && [regexp -nocase $man(outlinebut) $secttxt]))} {set closed ""}
$t tag configure area$now -elide $closed
# image create after add tag $now
$t image create "$now linestart" -image [expr {$closed==1? "closed":"opened"}]
$t tag add outline "$now linestart"
if {[regexp $manx(supregexp) $now] && $manx(mode$w)=="man"} {$t tag add alwaysvis "$now linestart" "$now lineend+1c"}
# && $man(subsect-show)!="never"
# $man(subsect-show)
# can't add "sc" tag in new syntax because want to pick up area$now tag in subsections
# on seaches, keep collapsed and show number of hits in each section? nah
set eol [$t index "$now lineend"]
if {$lcnt>0} {$t insert $eol " $lcnt"}
# if {$firstsect} {$t insert "$eol lineend" " lines"; set firstsect 0}
$t tag add sc $eol "$eol lineend"
}
$t configure -state disabled
}
# adjust priorities after flurry of tag creation
foreach tag [concat $manx(show-tags) hyper elide] {$t tag raise $tag}
# if {![string match "_*" $key] && $man(headfoot)!=""} {
if {$manx(mode$w)=="man" && $man(headfoot)!=""} {
$m add separator
$m add command -label "Header and Footer" -command "incr stat(page-section); $t yview endcontent"
#headfoot"
}
configurestate $mb
# [llength $ml]
manMenuFit $w.sections.m
# hyperlinks -- collect from manref tag sets by RosettaMan
## set refs [$t tag ranges manref]
## set reflist {}
## set m [set mb $w.links].m
## foreach {refstart refend} $refs {
## lappend reflist [$t get $refstart $refend]
## }
## foreach ref [uniqlist [lsort $reflist]] {
## $m add command -label $ref -command "incr stat(man-link); manShowMan $ref {} \$manx(out$w)"
## }
## configurestate $mb
# [llength $reflist]
## manMenuFit $m
# manHighlights $w get --> man pages want to attach highlights after diffs so offsets in menu accurate
manYview $w
# crucial "after" to prevent whole system from locking up!
# maybe works ok with Tcl 8.0 final; have to try that some time
after 100 focus $t
# focus $t
}
proc manYview {w} {
global manx man
set t $w.show
if [catch {set y $manx(yview,$manx(hv$w))}] {set y 1.0} else {manOutlineYview $t $y}
$t mark set xmark [$t index @0,0]
}
proc manOutlineYview {t line} {
if {[catch {$t index $line}] || [$t compare $line < 2.0]} return; # don't open top section when first show page
manOutline $t "" $line
$t yview $line
}
proc manOutlineSect {t sect} {
global manx curwin
if [catch {set now [$t index $sect]}] {return 0.0}
set new [lfirst $manx(sectposns$curwin)]
foreach try $manx(sectposns$curwin) {
if {[$t compare "$try linestart" > $now]} break
set new $try
}
return $new
}
# smart scrolling: try to expand sections rather than scrolling
# if unexpanded section on sixth line or later, expand
proc manDownSmart {w t} {
global manx
if {!$manx(tryoutline$w) || [lsearch {section apropos glimpse info} $manx(mode$w)]>-1 || [catch {$t index js1}]} {$t yview scroll 1 pages; return}
set sect $manx(cursect$t)
if {[$t bbox $sect]==""} {
set sect [manOutlineSect $t @0,0]
if {[$t bbox $sect]==""} {
set sect [lindex $manx(sectposns$w) [expr 1+[lsearch $manx(sectposns$w) $sect]]]
}
}
set x [lsearch $manx(sectposns$w) $sect]
while 1 {
set openme [lindex $manx(sectposns$w) $x]
if {$openme=="" || [$t bbox $openme]==""} {
$t yview scroll 1 pages
break
} elseif {[$t tag cget area$openme -elide]=="1"} {
manOutline $t 0 [set manx(cursect$t) $openme]
break
} else {incr x}
}
}
proc manOutline {t finv sect {prop 0}} {
global manx curwin
set time0 [clock clicks]
if {!$manx(tryoutline$curwin) || [string trim $sect]==""} return
# could be disconcerting, have to see how it wears
foreach tag $manx(show-ftags) {$t tag remove $tag 1.0 end}
# if explicitly playing with one section, don't subsequently open all of them
set manx(hitlist$t) {}
if {$sect=="*"} {
set sect $manx(sectposns$curwin)
}
if {[llength $sect]>1} {
foreach s $sect {manOutline $t $finv $s $prop}
return
} elseif ![string match "js*" $sect] {
# if not passed an outline tag, search for nearest previous one
if [catch {set now [$t index $sect]}] return
set sect [manOutlineSect $t $sect]
}
set oldfinv [$t tag cget area$sect -elide]
if {$finv==-1} {
set finv [expr {$oldfinv==""?1:""}]
} elseif {$finv==0} {set finv ""}
set sects $sect
if $prop {
set su $sect
# close up parents
if {$finv=="1"} {
while {[regexp $manx(supregexp) $su all sunum]} {lappend sects [set su "js$sunum"]}
# open up all children
} else {
set lev [regsub -all {\.} $sect {\.} junk]
foreach s [lrange $manx(sectposns$curwin) [expr 1+[lsearch $manx(sectposns$curwin) $sect]] end] {
if {[regsub -all {\.} $s {\.} junk] <= $lev} break
lappend sects $s
}
}
}
foreach s $sects {manOutline2 $t $finv $s}
# maintain context
if {$finv!=1} {
$t yview [set manx(cursect$t) $sect]
if {[$t dlineinfo $sect-5l]==""} {$t yview scroll -5 units}
}
# this is very fast now -- if $manx(mondostats) {manWinstdout $curwin "[lfirst [manWinstdout $curwin]] time [expr ([clock clicks]-$time0)/1000000.0] sec"}
}
proc manOutline2 {t finv sect} {
global man manx curwin texix$t stat
upvar #0 texix$t texix
# if showing, show parent too
if {$finv!=1} {
if [regexp $manx(supregexp) $sect all num] {manOutline2 $t $finv "js$num"}
}
if {[lsearch $manx(sectposns$curwin) $sect]==-1 || [lsearch -exact [$t tag names $sect] outline]==-1} return
set oldfinv [$t tag cget area$sect -elide]
if {$finv==$oldfinv} return
$t tag configure area$sect -elide $finv
set txtstate [$t cget -state]
$t configure -state normal
set inx "$sect linestart"
$t delete $inx
$t image create $inx -image [expr {$finv==1?"closed":"opened"}]
if {$manx(mode$curwin)=="man"} {$t tag add alwaysvis $inx}
#$man(subsect-show)!="never"
#$man(subsect-show)
$t tag add outline $inx
$t configure -state $txtstate
if {$finv==1} {incr stat(outline-collapse)} else {incr stat(outline-expand)}
# generalize this
# if Texinfo, may need to format (after expansion, otherwise have to search in nested elide)
if {$finv!=1 && $manx(mode$curwin)=="texi" && $texix($sect)!=""} {
set next [lindex $manx(nextposns$curwin) [lsearch $manx(sectposns$curwin) $sect]]
cursorBusy; $t configure -state normal
texiCallback $t $sect $next; # use anchored points to ease bookkeeping for texiMarkup
$t configure -state disabled; cursorUnset
scan [$t index end-1c] "%d" lastline
$curwin.search.cnt configure -text "$lastline lines"; # counts \n-terminated lines, sigh
}
}
proc manManPipe {f} {
global man manx
# if {$man(gtar)!="" && [regexp "(.*\.tar($manx(zregexp)?))/(.+)" $f all tar z subf]} {
# if {$z!=""} {set z "z"}
# set pipe "$man(gtar) -xO${z}f $subf"
# if {[regexp $manx(zregexp) $subf]} {append pipe " | $man(zcat)"}; # compress within tar
#
# } else
if {[regexp $manx(zregexp) $f] || [regexp $manx(zregexp) [file dirname $f]]} {
set pipe $man(zcat)
} else {set pipe "cat"}
return "$pipe $f"
}
# (proper) man page and text file finishings
proc manShowManStatus {w} {
global man manx pagecnt
set t $w.show; set wi $w.info
### update status information
# show section
manSetSect $w $manx(manfull$w)
# typein field
set manx(typein$w) $manx(name$w)
$w.mantypein icursor end
# history - save entire path, including any compression suffix
set manx(history$w) \
[lrange [setinsert $manx(history$w) 0 [list $manx(manfull$w)]] 0 [expr $man(maxhistory)-1]]
# should do this as a postcommand, but that's too messy
set m [set mb $w.history].m
$m delete 0 last
$m post 0 0; $m unpost; # needed to compensate for Tk menu bug
foreach i $manx(history$w) {
if {[llength [lfirst $i]]>=2} {set l [lfirst $i]} {set l $i}
if {![regexp {^[|<]} $l]} {set l [zapZ [file tail $l]]}
$m add command -label $l -command "incr stat(man-history); manShowMan $i {} $w"
}
configurestate $mb
# [llength $manx(history$w)]
manMenuFit $m
# shortcuts
manShortcutsStatus $w
# line count
scan [$t index end] "%d" linecnt
$w.search.cnt configure -text "$linecnt lines"
# page count statistics
set f [zapZ $manx(manfull$w)]
if ![string match "<*" $f] {set f [file tail $f]}
if ![info exists pagecnt($f)] {set pagecnt($f) [list 0 0 -1 0 [clock seconds]]}
foreach {times lasttime cksum nlines firsttime} $pagecnt($f) break
if {$firsttime==""} {set firsttime [clock seconds]}
if {$cksum==""} {set cksum -1}
set pagecnt($f) [list [expr 1+$times] [clock seconds] $cksum $linecnt $firsttime]
}
proc zapZ! {f} {
uplevel 1 set $f \[zapZ \[set $f\]\]
}
proc zapZ {f} {
global manx
return [expr {[regexp $manx(zregexp) $f]?[file rootname $f]:$f}]
}
#--------------------------------------------------
#
# manShowText -- use searching, etc. facilities for non-man page text
# to use via `send', pass full path name of text file to show
#
#--------------------------------------------------
proc manShowText {f0 {w .man} {keep 0}} {
global man manx stat
set wi $w.info
# maybe want to use `file' to check for ASCII files
# if {![file readable $f] || [file isdirectory $f]} {
# manWinstdout $w "Can't read $f"
# return
# }
set t $w.show
if {[string match <* $f0]} {
set f [fileexp [string range $f0 1 end]]
if {[regexp $manx(zregexp) $f]} {set f "|$man(zcat) $f"}
# {set f "|cat $f"}
} else {set f [pipeexp $f0]}
# strain out control characters and show nroff files
# append f " | rman"
manNewMode $w txt; incr stat(txt)
manTextOpen $w
if {[catch {
set fid [open $f]
$t insert end [read $fid]
close $fid
}]} {manTextClose $w; manWinstderr $w "Trouble reading $f0"; return}
manTextClose $w
if {!$keep} {pack forget $w.dups}
if [file isfile $f] {cd [file dirname [glob $f]]}
### update status information
# could always save full path here, but that occupies too much screen real estate
set manx(man$w) $f0
set manx(num$w) X
set manx(hv$w) [bolg [zapZ $f] ~]
set manx(manfull$w) $f0
set manx(catfull$w) $f
set manx(name$w) $f0
manShowManStatus $w
manWinstdout $w $manx(manfull$w)
manHighlights $w get; manYview $w
focus $t
return $f
}
#--------------------------------------------------
#
# manShowTexi -- use searching, etc. facilities for non-man page text
# to use via `send', pass full path name of text file to show
#
#--------------------------------------------------
proc manShowTexi {f0 {w .man} {keep 0}} {
global man manx stat
set t $w.show
set wi $w.info
set f $f0
if {[regexp $manx(zregexp) $f]} {set f "|$man(zcat) $f"}
# manNewMode $w texi; incr stat(texi)
manNewMode $w section; incr stat(texi)
# set loading [clock clicks]
manTextOpen $w
texiShow $t $f $man(texinfodir)
manTextClose $w
# puts "loaded in [expr ([clock clicks]-$loading)/1000000.0] sec"
if {!$keep} {pack forget $w.dups}
# if all marks under chapter 1 (or 0), raise everyone up a level => just be robust to missing hierarchy
### update status information
# could always save full path here, but that occupies too much screen real estate
set manx(man$w) $f0
set manx(num$w) X
set manx(hv$w) [bolg [zapZ $f] ~]
set manx(manfull$w) $f0
set manx(catfull$w) $f
set manx(name$w) $f0
# Texinfo outline shows number of subsections (more useful than number of lines)
# set outline [clock clicks]
manShowManFoundSetText $w $t $manx(hv$w)
manShowManStatus $w
# foreach tag [lrange $manx(outline-show-v) 1 end] {$t tag raise $tag}
# puts "outlining in [expr ([clock clicks]-$outline)/1000000.0] sec"
manWinstdout $w $manx(manfull$w)
# manHighView $w
# focus $t -- done by manShowManFoundSetText
return $f
}
#--------------------------------------------------
#
# manShowRfc -- use searching, etc. facilities for non-man page text
# to use via `send', pass full path name of text file to show
#
#--------------------------------------------------
proc manShowRfc {f0 {w .man} {keep 0}} {
global rfcmap stat
manNewMode $w rfc; incr stat(rfc)
manShowText $f0 $w $keep
# manShowMan "$man(rfcdir)$rfcmap($num)/rfc$num.txt"
# one-time long wait (<10 sec) when show full list, then instant
# [find $man(rfcdir) "\[string match rfc.txt \$file]" {[llength $findx(matches)]==0 && $depth<=3}]
# strip out page headers/footers
set t $w.show
set state [$t cget -state]
$t configure -state normal
while {[$t get 1.0]=="\n"} {$t delete 1.0}
set index 1.0
while {[set index [$t search -forwards -regexp "^\f" $index end]]!=""} {
#puts "back @ $index"
scan [$t index "$index linestart -1l"] "%d" back
while {[$t get $back.0]!="\n"} {incr back -1}
while {[$t get $back.0]=="\n"} {incr back -1}
incr back
#puts "forward @ $index"
scan [$t index "$index linestart +1l"] "%d" forward
while {[$t compare $forward.0 < end] && [$t get $forward.0]!="\n"} {incr forward}
while {[$t compare $forward.0 < end] && [$t get $forward.0]=="\n"} {incr forward}
incr forward -1
$t delete $back.0 "$forward.0 lineend"; # keep a \n separation (sometimes right, sometimes wrong)
}
# outline -- can't parse
#puts "outline"
if 0 {
set index 1.0
set js 1
while {[$t get $index]!=" "} {set index [$t index $index+1l]}
while {[set index [$t search -forwards -regexp {^[^ ]} $index+1l end]]!=""} {
#puts "outline js$js @ $index"
$t mark set js$js $index; incr js
# $t tag add search $index
}
#puts "done"
manShowManFoundSetText $w $t $f0
}
$t configure -state $state
return $f0
}
#--------------------------------------------------
#
# manApropos -- show `apropos' (`man -k') information, w/dups filtered out, reformatted
#
#--------------------------------------------------
proc manApropos {name {w .man}} {
global man manx mani stat
if $manx(shift) { set manx(shift) 0; set w [manInstantiate] }
set wi $w.info; set t $w.show
if {$name==""} {set name $manx(man$w)}
if {$name==""} {
manWinstderr $w "Type in keywords to search for"
return
}
set form {}
lappend form " Apropos search for \"$name\"\n\n" {}
manWinstdout $w "Apropos search for \"$name\" ..." 1
DEBUG {puts "manApropos: exec $man(apropos) $name $man(aproposfilter) 2>/dev/null"}
if {[catch {set tmp [eval exec "$man(apropos) $name $man(aproposfilter) 2>/dev/null"]} info] || [string trim $tmp]==""} {
if {$info!=""} {
lappend form $info i
} else {
lappend form "Nothing related found.\n" i
}
if {$man(glimpse)!=""} { lappend form "Try a full text search with Glimpse.\n" {}}
set mani(apropos,cnt) 0
} else {
manNewMode $w aprops; incr stat(apropos)
set mani(apropos,update) [clock seconds]
set cnt 0
foreach line [split $tmp "\n"] {
# zap formatting codes if erroneously given roff source
regsub "^\\.\[^ \t\]+" $line "" line
# normalize tabs
regsub -all "\[\t \]+" $line " " line
# normalize spacing between names and descriptions to single tab
regsub " - " $line "\t - " line
# some idiot apropos index maker puts in "}}} {{{" before text excerpt
regsub -all {[][{}"]} $line "" line
# Solaris gives name of file, name of function within page
if {[lfirst $line]==[lsecond $line]} { regsub {^[ ]*[^ ]+[ ]*} $line "" line }
if {[regexp "(\[^\t]+)\t+(.*)" $line all cmds desc]} {
} elseif {[regexp "(.+) +(.*)" $line all cmds desc]} {
} else {set cmds [lindex $line 0]; set desc [lrange $line 1 end]}
# foreach {cmds desc} [split $line "\t"] {} -- some apropos binaries don't write spaces?
lappend form $cmds manref "\t$desc\n" {}
#$line "\n"
incr cnt
}
.vols entryconfigure "apropos*" -state normal
# -label "apropos hit list ($cnt for \"$name\")"
set mani(apropos,cnt) $cnt
set manx(yview,apropos) 1.0
}
set mani(apropos,form) $form
set mani(apropos,shortvolname) "apropos"
manShowSection $w apropos
}
#--------------------------------------------------
#
# manHelp -- dump help text that's "compiled" offline
#
#--------------------------------------------------
proc manHelp {w} {
global man manx stat tk_library
set t $w.show; set wi $w.info
manNewMode $w help; incr stat(help)
wm title $w "$manx(title$w) v$manx(version)"
set manx(manfull$w) "_help"
set manx(name$w) "_help"
manTextOpen $w
# put in help first so marks set correctly (they stay correct subsequently as they float)
manHelpDump $t
# fixups
$t tag remove h1 1.0 "1.0 lineend"; $t tag add title 1.0 "1.0 lineend"
$t delete 2.0
# set copyright [$t search "(c)" 1.0]
# $t delete $copyright $copyright+3c; $t insert $copyright "\251"; $t tag add symbol $copyright
$t image create 2.0 -image icon -padx 8 -pady 8
$t mark set insert "author1+2lines lineend"
$t insert insert "\t"
$t image create insert -image face -align bottom -padx 8 -pady 8
set demo [file join $tk_library demos widget]
if [file executable $demo] {
button $t.demo -text "run Tcl/Tk demo" -foreground $man(textfg) -background $man(textbg) -font $man(textfont) \
-command "exec \[info nameofexecutable\] $demo &"
$t window create [list [$t search "Ousterhout" 1.0] lineend] -window $t.demo -align bottom -padx 8
}
# now add to opening screen
# update warnings
manManpathCheck
set fWarn 0
foreach warn {manpathset manpath mandesc expire} {
if {$manx($warn-warnings)!=""} {
$t insert 1.0 $manx($warn-warnings)\n\n
set fWarn 1
}
}
if $fWarn { $t insert 1.0 "Warnings\n\n" b }
$t insert 1.0 $manx(updateinfo)
manTextClose $w
# translate SGML names to Tk marks
set sectcnt 0; set subsectcnt 0
foreach i [lsort -command "bytextposn $t " [$t mark names]] {
# foreach i [lsortbytextposn $t [$t mark names]] {
# can't ever do this because need numbers in, names out: foreach i [lsort -dictionary [$t mark names]] {
if {[string match "*1" $i]} { $t mark set js[incr sectcnt] $i; set subsectcnt 0; $t mark unset $i }
if {[string match "*2" $i]} { $t mark set js$sectcnt.[incr subsectcnt] $i; $t mark unset $i }
}
manShowManFoundSetText $w $t "_help"
manShowTagDist $w h2
manHighlights $w get
# use update and after for good interaction with rebuilding database
update idletasks
after 1 "manWinstdout $w \"TkMan v$manx(version) of $manx(date)\""
}
proc bytextposn {t a b} {
return [expr {[$t compare $a < $b]?-1:[$t compare $a > $b]}]
}
#proc lsortbytextposn {t names} {
# set tuples {}
# foreach n $names {lappend tuples [list [$t index $n] $n]}
# set sorted [lsort -dictionary $nums -index 0]
# set sortnames
#}
#--------------------------------------------------
#
# manKeyNav -- keyboard-based navigation and searching
# calls out to searchbox module
#
#--------------------------------------------------
proc manKeyNav {w m k} {
global man manx
set t $w.show; set wi $w.info
if [catch {set isearch [$t index isearch.first]}] {set isearch -1}
set firstmode [expr {$manx(mode$w)=="section" || $manx(mode$w)=="apropos"}]
set casesen [expr $firstmode?1:$man(incr,case)]
set fFound [searchboxKeyNav $m $k $casesen $t $wi $firstmode [expr {$manx(tryoutline$w)?"-elide":""}]]
# if {!$fFound && $firstmode} {set fFound [searchboxKeyNav $m $k 0 $t $wi $firstmode]}
if [catch {set isearch2 [$t index isearch.first]}] {set isearch2 -1}
if {$isearch2!=-1 && $isearch!=$isearch2} {manOutlineYview $t isearch.first}
return $fFound
}
#--------------------------------------------------
#
# manSave -- manage merging with old config file
# if passed name of save file, could put this into utils
#
#--------------------------------------------------
proc manSave {} {
global man manx env
if {$manx(savegeom)} {set man(geom) [wm geometry .man]}
set w [manPreferencesMake]
if [winfo exists $w] {set man(geom-prefs) [geom2posn [wm geometry $w]]}
set nfn $manx(startup)
set ofn $manx(startup)-bkup
if {![file exists $nfn] || [file writable $nfn]} {
if {[file exists $nfn]} {file copy -force $nfn $ofn}
if [catch {set fid [open $nfn w]}] {
manWinstderr .man "$nfn is probably on a read-only filesystem"
return
}
foreach p [info procs *SaveConfig] {eval $p $fid}
puts $fid "manDot\n"
puts $fid $manx(userconfig)
if {[file exists $ofn]} {
set ofid [open $ofn]
set p 0
while {[gets $ofid line]!=-1} {
if {$p} {puts $fid $line} \
elseif {$manx(userconfig)=="$line"} {set p 1}
}
close $ofid
}
close $fid
}
# don't delete ~/.oldtkman
}
#--------------------------------------------------
#
# manSaveConfig -- dump persistent variables into passed file id
#
#--------------------------------------------------
proc manSaveConfig {fid} {
global man manx high default
# if only persistent stuff in man array,
# could have general SaveConfig in utils.tcl
# write out preamble
puts $fid "#\n# TkMan v$manx(version)"
# insert $env(USER)?
puts $fid "# configuration saved on [clock format [clock seconds]]"
puts $fid "#\n"
set preamble {
Elements of the man array control many aspects of operation.
Most, but not all, user-controllable parameters are available
in the Preferences panel. All parameters are listed below.
Those that are identical to their default values are commented
out (preceded by \"#\") so that changes in the defaults will propagate nicely.
If you want to override the default, uncomment it and change the value
to its new, persistent setting.
}
foreach line [split [linebreak $preamble] "\n"] {
puts $fid "# $line"
}
puts $fid ""
# save miscellaneous variables
manStatsSet; # update its value
# write out man(), commenting out if same as corresponding default()
# maybe iterate through default array ==> no! won't pick up man(/<directory>)'s
foreach i [lsort [array names man]] {
if {[info exists default($i)]} {
if {$default($i)==$man($i)} {set co "#"} {set co ""}
puts $fid "${co}set [list man($i)] [tr [list $man($i)] \n \n$co]"
} elseif {[string match "/*" $i]} {puts $fid "set man($i) $man($i)"}
}
puts $fid "\n\n#\n# Highlights\n#\n"
# puts $fid "# format: time, start/end pairs for use by text widget"
foreach i [lsort [array names high]] {
puts $fid "set [list high($i)] [list $high($i)]"
}
puts $fid "\n"
}
#--------------------------------------------------
#
# manStats* -- cumulative statistics
#
#--------------------------------------------------
# write out new stats line
proc manStatsSaveFile {} {
global man manx
DEBUG {puts -nonewline "manStatsSaveFile"}
# if flag not set, don't bother
if {$manx(statsdirty) && [file readable $manx(startup)] && [file writable $manx(startup)]} {
# read in file
set fid [open $manx(startup)]; set startup [read $fid]; close $fid
manStatsSet
foreach var {stats pagecnt} {
set stats "set man($var) [list $man($var)]\n"
# rewrite variable or instantiate new variable before userconfig, if such a line exists
if [regsub "set man\\($var\\)\[^\}\]+\}\n" $startup $stats nstartup] {
# if [regsub "set man\\($var\\).*\n\}\n" $startup $stats nstartup] -- eats too much!
# problem copying from and into same variable, though seems to work in other cases
set startup $nstartup
#puts "\n$startup\n"
DEBUG {puts -nonewline "\tfound existing variable"}
} elseif [regsub "\n\n$manx(userconfig)\n" $startup "\n\n$stats\n$manx(userconfig)\n" nstartup] {
set startup $nstartup
DEBUG {puts -nonewline "\tinserted before userconfig"}
} else {
append startup $stats
DEBUG {puts -nonewline "\tappended"}
}
}
# write it out
set fid [open $manx(startup) "w"]; puts -nonewline $fid $startup; close $fid
DEBUG {puts -nonewline "\tsaved to file"}
}
DEBUG {puts ""}
after [expr 5*60*1000] manStatsSaveFile
# after [expr 5*1000] manStatsSaveFile
}
# save as name-value pairs so can extend list without positional dependencies leading to madness
set man(prof) {}
proc manStatsSet {} {
global man manx stat pagecnt short prof
DEBUG {puts "manStatsSet"}
trace vdelete stat w manStatsDirty
trace vdelete pagecnt w manStatsDirty
scan $man(stats) "%d" stat(cum-time)
set newstats $stat(cum-time)
# simple profile statistics
set tmp {}
foreach p [array names prof cnt-*] {
set name [string range $p 4 end]
lappend tmp [list $name $prof(cnt-$name) $prof(totaltime-$name)]
}
set man(prof) ""
set cnt 0
foreach p [lsort -decreasing -real -index 2 $tmp] {
set name [lfirst $p]
append man(prof) "\n\t" $name " \"$prof(cnt-$name) $prof(totaltime-$name)\""
incr cnt
}
append man(prof) "\n"
# bump up monolithic cumulative
foreach i $manx(all-stats) {
# get cumulative value
if {[set index [lsearch $man(stats) $i]]>=0} {
set stat(cum-$i) [lindex $man(stats) [expr $index+1]]
} else {
set stat(cum-$i) $stat($i)
}
# bump up cumulative totals
incr stat(cum-$i) [expr $stat($i)-$stat(cur-$i)]
set stat(cur-$i) $stat($i)
lappend newstats $i $stat(cum-$i)
}
set man(stats) $newstats
# shortcuts
set man(shortcuts) {}
foreach i $manx(shortcuts) {lappend man(shortcuts) [list $i $short($i)]}
# page counts
set man(pagecnt) ""
set cnt 0
# store in frequency order, so someone can easily delete entries with low counts to save space
# create list
set tmp {}
foreach name [array names pagecnt] {lappend tmp [concat $name $pagecnt($name)]}; # want a destructive concat
foreach i [lsort -index 1 -integer -decreasing $tmp] {
set name [lfirst $i]
# can't have sublists (sneaky stats regexp), but ok to put numbers in quotes
append man(pagecnt) [expr {$cnt%2==0? "\n\t": " "}] $name " \"$pagecnt($name)\""
# aw, all real editors can handle long lines
#lappend man(pagecnt) $name [lfirst $pagecnt($name)] [lsecond $pagecnt($name)]
incr cnt
}
append man(pagecnt) "\n"
# for counts of browses, update last element
set newchrono [lreplace $man(chronobrowse) end end "$manx(startuptime)/[expr [clock seconds]-$manx(startuptime)]:$stat(man)/$stat(texi)/$stat(rfc)"]
set man(chronobrowse) "\n\t"
set cnt 0
foreach tuple $newchrono {
incr cnt
append man(chronobrowse) $tuple [expr {$cnt%4==0? "\n\t": " "}]
}
append man(chronobrowse) "\n"
trace variable stat w manStatsDirty
trace variable pagecnt w manStatsDirty
set manx(statsdirty) 0
}
# set trigger of writes to stat array to set flag
proc manStatsDirty {name1 name2 op} {
global manx mani
DEBUG {puts "manStatsDirty: $name2"}
set manx(statsdirty) 1
# set mani(census,form) "" -- cleared before shown, but keep for random
}
#--------------------------------------------------
#
# Startup initialization and validity checks
#
#--------------------------------------------------
# after reading .tkman variables but before executing code
proc manDot {} {
global manx
manManManx
manPresDefaultsSet
# make window here so ~/.tkman commands can manipulate it without `after'
toplevel .man -class TkMan
manPreferencesGet fill
set manx(manDot) 1
}
proc manManManx {} {
global man manx
# these get set to man counterparts, unless overwritten by command line options
foreach i {
iconify iconname iconbitmap iconmask iconposition
geom
#glimpsestrays
} {
if {![info exists manx($i)]} {set manx($i) $man($i)}
}
}
#
# check for existence of supporting executables, with right versions
# this information usually fine, usually just taxing startup time,
# so defer to a thread. So have to wait a little for Statistics, who cares?
#
proc manBinCheck {{inx 0} {err 0}} {
global man manx env stat
# set homebin $env(HOME)/bin
# set needmybin [expr {[file readable $homebin] && [llength [glob -nocomplain $homebin]]>0}]
# if person dosn't have ~/bin in PATH, he should know about it already (as compared to ~/man)
# binaries checks for rman, sed, ...
set var [lindex $manx(binvars) $inx]
set val [set $var]
if {$val!=""} {
DEBUG {puts "manBinCheck on $var"}
# first check for existence and executability...
foreach pipe [split $val "|"] {
set bin [lfirst $pipe]
set found 0
#; set exe 0
#puts stderr "checking $var's $bin"
if {[string match "/*" $bin]} {set pathlist [file dirname $bin]; set tail [file tail $bin]
} else {set pathlist $manx(bin-paths); set tail $bin}
foreach dir $pathlist {
if {$dir=="."} continue
set fullpath $dir/$tail
# ignore file if not executable, just like shells do
if {[file isfile $fullpath] && [file executable $fullpath]} {
set found 1
# if {[file executable $fullpath]} {set exe 1}
#puts stderr "\tfound @ $dir"
set stat(bin-$bin) $fullpath
DEBUG { puts "$bin => $fullpath" }
break
}
}
if {!$found} {
puts stderr "$bin not found in your PATH--check the $var variable in $manx(startup) or the Makefile."
incr err
# } elseif {!$exe} {
# puts stderr "$bin found but not executable--check permissions."
# incr err
} else {
# ... then check for proper versions of selected executables
if {[set info [lassoc $manx(bin-versioned) $tail]]!=""} {
# lset $info flag minvers
foreach {flag minvers} $info {}
# use 2> /dev/null because glimpseindex triggers error message on FreeBSD
set execerr [catch {set lines [exec $fullpath $flag < /dev/null 2> /dev/null]} info]
} elseif {[string match "g*" $tail]} {
# could be a GNU -- maybe take this out since it lengthens startup for all in exchange for small benefit for few
set minvers 0.0
#foreach flag {"--version" "-V" "-v"} -- takes to long to start up
# GNU programs print version information to stderr; should be stdout
set execerr [catch {set lines [exec $fullpath $flag < /dev/null]} info]
set execerr 0; set lines $info
} else continue
if {$execerr && $minvers==0.0} {
# nothing
} elseif {$execerr} {
puts "ERROR executing \"$fullpath $flag\": $info\a"
incr err
} else {
set line ""; foreach line [split $lines "\n"] { if {$line!=""} break }
# grok version number
set vers unknown
if {$line=="" || ![regexp $manx(bin-versregexp) $line vers cmpvers] || [package vcompare $minvers $cmpvers]==1} {
if {$minvers!=0.0} {
puts stderr "$bin is version $vers--must be at least $minvers."
incr err
}
} else { set stat(bin-$bin-vers) $vers }
}
}
}
}
# chain to next one
incr inx
if {$inx<[llength $manx(binvars)]} {
after 1000 manBinCheck $inx $err
} else {
if {$err} {exit 1}
.occ entryconfigure "Statistics*" -state normal
}
# if [string match "3*" $stat(bin-rman-vers)] {set manx(rman-source) 1}
}
proc manParseCommandline {} {
global manx argv argv0 env geometry
for {set i 0} \$i<[llength $argv] {incr i} {
set arg [lindex $argv $i]; set val [lindex $argv [expr $i+1]]
switch -glob -- $arg {
-help -
-h* -
--help {
set helptxt {
[-M <MANPATH>] [-M+ <paths to append to MANPATH>] [-+M <paths to prepend to MANPATH>]
[-[!]iconify] [-version]
[-title <string>] [-startup <file>] [-[!]debug] [<man page>[(<section>)]]
}
puts -nonewline "tkman"
foreach line [split [linebreak $helptxt 70] "\n"] { puts "\t$line" }
exit 0
}
-M {set env(MANPATH) $val; incr i}
-M+ {append env(MANPATH) ":$val"; incr i}
-+M {set env(MANPATH) "$val:$env(MANPATH)"; incr i}
-dpi {set manx(dpi) $val; lappend manx(dpis) $val; incr i}
-iconname {set manx(iconname) $val; incr i}
-iconmask {set manx(iconmask) $val; incr i}
-iconposition {set manx(iconposition) $val; incr i}
-iconbitmap {set manx(iconbitmap) $val; incr i}
-icon* {set manx(iconify) 1}
-noicon* {set manx(iconify) 0}
-quit {if [string match no* $val] {set manx(quit) 0}; incr i}
# put the more permissive option name patterns down below
-start* {set manx(startup) $val; incr i}
-data* {puts stderr "-database option obsolete: database kept in memory"; incr i}
--v* -
-v* {puts stdout "TkMan v$manx(version) of $manx(date)"; exit 0}
-t* {set manx(title) $val; incr i}
-d* {set manx(debug) 1; set manx(quit) 0; set manx(iconify) 0}
-nod* {set manx(debug) 0}
-* {puts stdout "[file tail $argv0]: unrecognized option: $arg"; exit 1}
default {
after 2000 manShowMan $arg {{}} .man
# permit several??? add extras to History?
break
}
}
}
# grr, special case
if {[info exists geometry]} {set manx(geom) $geometry}
}
proc ASSERT {args} {
if {![uplevel 1 eval $args]} {
puts "ASSERTION VIOLATED: $args"
exit 1
}
}
proc DEBUG {args} {
global manx
if $manx(debug) {uplevel 1 eval $args}
}
##################################################
###
### start up
###
##################################################
### environment checks
if {[info tclversion]<$manx(mintcl) || $tk_version<$manx(mintk)} {
puts -nonewline stderr "Tcl $manx(mintcl)/Tk $manx(mintk) minimum versions required. "
puts stderr "You have Tcl [info tclversion]/Tk $tk_version"
exit 1
} elseif {int([info tclversion])-int($manx(mintcl))>=1 || int($tk_version)-int($manx(mintk))>=1} {
puts stderr "New major versions of Tcl and/or Tk may have introduced\nincompatibilies in TkMan.\nCheck the TkMan home ftp site for a possible new version.\n"
}
#--------------------------------------------------
#
# set defaults for shared global variables
#
#--------------------------------------------------
# # # # # # # # # # # # # # # # # # # # # # # # # #
# DON'T EDIT THE DEFAULTS HERE--DO IT IN ~/.tkman #
# # # # # # # # # # # # # # # # # # # # # # # # # #
# man() = persistent variables
# manx() = x-pire, system use, command line overrides
set curwin [set w .man]
#
# man
#
set man(manList) {1 2 3 4 5 6 7 8 9 l o n p D}
set man(manTitleList) {
"User Commands" "System Calls" Subroutines
Devices "File Formats"
Games "Miscellaneous" "System Administration" "*** check contrib/*_bindings ***"
Local Old New Public "*** check contrib/*_bindings ***"
}
set man(stats) [clock seconds]
set man(time-lastglimpse) -1
#set man(time-lasttexinfo) -1
set manx(styles) {normal bold italics bold-italics}
set manx(pts) {8 9 10 12 14 18 24 36}
set manx(sizes) {tiny small medium large larger huge}
set man(gui-family) "Times"
set man(gui-style) "bold"
set man(gui-points) "small"
set man(text-family) "New Century Schoolbook"
set man(text-style) "normal"
set man(text-points) "small"
set man(vol-family) "Times"
set man(vol-style) "normal"
set man(vol-points) "small"
#foreach f {diffa diffc diffd} {set man($f-family) $man(text-family)}
set man(diffd-style) "normal"
set man(diffc-style) "bold-italics"
set man(diffa-style) "italics"
set man(textfont) textpro
set manx(fontfamilies) [lsort [string tolower [font families]]]
### general tags
set man(isearch) {-background gray}
#set man(search) reverse
set man(search) {-background orange}; # eye-catching but not overbearing on long stretches
set man(cmd) {-background green}
set man(spot) {-background red}
set man(manref) {sanserif -foreground blue}
#set man(manrefseen) {sanserif -foreground #00C} -- not useful
# -underline yes}
set man(hot) {-foreground red}
# -underline yes}
set man(highlight) {-background #ffd8ffffb332}; # a pale yellow
set man(indent) {-lmargin1 5m -lmargin2 10m}
set man(indent2) {-lmargin1 10m -lmargin2 15m}
### Texinfo tags
# don't need to have named fonts for tags
set manx(tags) {diffa diffd diffc title h1 h2 h3 tt t sc y b bi i highlight highlight-meta search isearch cmd manref hot indent indent2 spot
r asis example display table subscript superscript lisp smalllisp code kbd key file var emph author strong dfn chapter section subsection subsubsection majorheading titlefont heading subheading subsubheading w deffn defun defmac defspec quotation index cite subtitle author flushleft flushright center cartouche
tcl tclcomment tclkeyword texixref rfcxref
}
#set man(diffa) {-font diffa}
#set man(diffc) {-font diffc}
#set man(diffd) {-font diffd -overstrike yes}
#set man(diffa) {"$man(diffa-family)" "$man(diffa-style)"}
#set man(diffc) {"$man(diffc-family)" "$man(diffc-style)"}
#set man(diffd) {"$man(diffd-family)" "$man(diffd-style)" -overstrike yes}
set man(diffa) {"$man(diffa-style)"}
set man(diffc) {"$man(diffc-style)"}
set man(diffd) {"$man(diffd-style)" -overstrike yes s}
#set man(diffbar) "yes"; set manx(diffbar-v) {1 0}; set manx(diffbar-t) {"yes" "no"}
set man(strike) {-overstrike yes}
set man(tt) [set man(t) mono]
set man(sc) s
set man(y) symbol
set man(b) bold
set man(bi) bold-italics
set man(i) italics
set man(title) {bold large l}
set man(h1) {bold l}
set man(h2) {bold m}
# -spacing3 3}
set man(h3) {bold s}
set man(h4) {s}
# h1,h2,h3,h4 <=> chapter,section,subsection,subsubsection
#italics
# Texinfo -- should give this to texi.tcl
set man(r) {}
# set man(format) {} -- NO! conflicts with nroff formatting pipe!
set man(asis) {}
set man(example) {mono small s -wrap none -tabs 0.3i}
set man(display) {-lmargin1 0.3i -lmargin2 0.3i -rmargin 0.3i}
set man(table) {-tabs 0.3i -lmargin2 0.3i}
set man(subscript) {-offset -3}
set man(superscript) {-offset 3}
set man(lisp) {mono small s -wrap none}
set man(smalllisp) {mono small s -wrap none}
set man(code) {mono}
set man(kbd) {mono}; set man(key) $man(sc)
set man(url) {mono}
set man(file) {italics}
set man(var) {italics}
set man(emph) {italics}
set man(strong) {bold}
set man(deffn) {italics}
set man(defun) {italics}
set man(defmac) {italics}
set man(defspec) {italics}
set man(author) {bold}
set man(dfn) {bold}
set man(chapter) [set man(majorheading) [set man(titlefont) {bold m}]]
set man(section) [set man(heading) {bold s}]
set man(subsection) [set man(subheading) {italics}]
set man(subsubsection) [set man(subsubheading) {}]
set man(cite) {italics}
set man(cartouche) {-borderwidth 2}
set man(subtitle) {italics}
set man(author) {bold}
set man(center) {center}
set man(flushleft) {left}
set man(flushright) {right}
set man(w) {}
#-wrap none} -- affects whole line or nothing
set man(quotation) {-lmargin1 0.5i -lmargin2 0.5i -rmargin 0.5i}
set man(index) {s -tabs 3i}
set man(texixref) $man(manref)
set man(rfcxref) $man(manref)
set man(tcl) {-tabs 0.2i -font {Courier 10}}
set man(tclcomment) {-background yellow}
set man(tclkeyword) {bold}
set man(maxhistory) 15; set manx(maxhistory-v) [set manx(maxhistory-t) {5 10 15 20 30 40 50}]
set man(recentdays) 14; set manx(recentdays-v) [set manx(recentdays-t) {1 2 7 14 30 60 90 180}]
set man(pagecnt) {}
set man(chronobrowse) {}
# seed shortcuts with set for the beginner? then expert has to remove them all
set man(shortcuts) {}
set man(shortcuts-sort) 0; set manx(shortcuts-sort-v) {1 0}; set manx(shortcuts-sort-t) {"alphabetical" "chronological"}
#set man(indexglimpse) "distributed"; -- now set in Makefile
set manx(indexglimpse-v) [set manx(indexglimpse-t) {"distributed" "unified"}]
set man(incr,case) -1; set manx(incr,case-v) {1 0 -1}; set manx(incr,case-t) {"yes" "no" "iff upper"}
set man(regexp,case) -1; set manx(regexp,case-v) {1 0 -1}; set manx(regexp,case-t) {"yes" "no" "iff upper"}
set man(maxglimpse) 200; set manx(maxglimpse-v) [set manx(maxglimpse-t) {25 50 100 200 500 1000 "none"}]
set man(maxglimpseexcerpt) 50; set manx(maxglimpseexcerpt-v) [set manx(maxglimpseexcerpt-t) {25 50 100 200 500 1000}]
#set man(whatwhere) 1; set manx(whatwhere-v) {1 0}; set manx(whatwhere-t) {"pathname" "description"}
set man(iconify) 0; set manx(iconify-v) {1 0}; set manx(iconify-t) {"yes" "no"}
set man(subsect) ""; set manx(subsect-v) {"-b" ""}; set manx(subsect-t) {"yes" "no"}
set man(nroffsave) "off"; set manx(nroffsave-v) [set manx(nroffsave-t) {"on" "on & compress" "off" "off & ignore cache"}]
set man(headfoot) "-k"; set manx(headfoot-v) {"-k" ""}; set manx(headfoot-t) {"yes" "no"}
set man(hyperclick) "single"; set manx(hyperclick-v) [set manx(hyperclick-t) {"double" "single"}]
set man(fsstnddir) /var/catman
set man(aproposfilter) {| sort | uniq}
set man(scrollbarside) right; set manx(scrollbarside-v) [set manx(scrollbarside-t) {"left" "right"}]
set man(documentmap) 1; set manx(documentmap-v) {1 0}; set manx(documentmap-t) {"yes" "no"}
# zap hyphens automatically in SEE ALSO and in groff; otherwise don't
#set man(zaphy) ""; set manx(zaphy-v) {"-y" ""}; set manx(zaphy-t) {"yes" "no"}
set man(strictmotif) 0; set manx(strictmotif-v) {1 0}; set manx(strictmotif-t) {"yes" "no"}
set man(subvols) 1; set manx(subvols-v) {1 0}; set manx(subvols-t) {"yes" "no"}
set man(preferGNU) ""; set manx(preferGNU-v) {"g?" ""}; set manx(preferGNU-t) {"yes" "no"}
set man(search,fcontext) 0; set manx(search,fcontext-v) [set manx(search,fcontext-t) {0 1 2 3 4 5}]
set man(search,bcontext) 0; set manx(search,bcontext-v) [set manx(search,bcontext-t) {0 1 2 3 4 5}]
set man(textboxmargin) 5; set manx(textboxmargin-v) [set manx(textboxmargin-t) {0 1 2 3 4 5 7 10}]
set man(error-effect) "bell & flash"; set manx(error-effect-v) [set manx(error-effect-t) {"bell & flash" "bell" "flash" "none"}]
set man(columns) 65; set manx(columns-v) {65 90 130 5000}; set manx(columns-t) {"65 (most compatible)" 90 130 "linebreak at paragraph"}; # no one would want shorter lines
set manx(longtmp) /tmp/ll
set man(volcol) 4.0c; set manx(volcol-v) {0 1.5c 2.0c 2.5c 3.0c 3.5c 4.0c 4.5c 5.0c 7.5c 10.0c}; set manx(volcol-t) {"no columns" "1.5 cm" "2 cm" "2.5 cm/~1 inch" "3 cm" "3.5 cm" "4 cm" "4.5 cm" "5.0 cm/~2 inches" "7.5 cm" "10 cm"}
set man(apropostab) "4.5c"; set manx(apropostab-v) {0 3.0c 4.0c 4.5c 5.0c 5.5c 6.0c 7.5c 10.0c}; set manx(apropostab-t) {"none" "3 cm" "4 cm" "4.5 cm" "5 cm" "5.5 cm" "6 cm" "7.5 cm" "10 cm"}
#set man(changeleft) "-c"
#set man(showoutsub) ""
#set man(reflow) "" -- doesn't work reliably. have to go with source
set man(prefersource) 1
#set man(rman-source) 0; # can rman handle source? -- always format
#set man(tables) ""; set manx(tables-v) {"-T" ""}; set manx(tables-t) {"on" "off"}
set man(high,hcontext) 50
set man(high,vcontext) 10; set manx(high,vcontext-v) [set manx(high,vcontext-t) {0 2 5 7 10 15 20}]
text .outline
if [catch {.outline tag configure test -elide 1}] {
puts "Elide patch not installed in [info nameofexecutable].\nYou must apply the elided text patch to Tk and rebuild wish.\nSee the Makefile for more information.\n"
exit 1
}
destroy .outline
set man(outline) "allbut"; set manx(outline-v) {"allexp" "allcol" "allbut" "off"}; set manx(outline-t) {"all expanded" "all collapsed" "all collapsed but" "none"}
# "allbutplus" => superceded by outlinebut matches with line counts
# "all but, plus fit"
# usually want description, but many descriptions are long (the bulk of the page) and would push off good stuff at bottom
#set man(outlinebut) {^name[0-9]+$|synopsis|(author|credits)|(see also|related information)}
# long Name, short Description, short Synopsis, short See Also
set man(outlinebut) {^name[0-9]+$|(syntax|synopsis)[1-2]?[0-9]$|description[0-9]$|(author|identification|credits)[^0-9]*[1-9]$|(see also|related information)1?[0-9]$}
# -nocase
#set man(outlinebutfirst) {synopsis} -- outlinebutfirst obsolete
# DON'T ADD THESE TO man(autosearch)
# @ - either no email or million in list of contributors + many false hits
# priority -
# Maybe but decided against
# version, postscript - just too frequent on some pages
set man(autosearch) {unsafe|warning|danger|difficult|tricky|obsolete|international|english|posix|texinfo|html|web|performance|solaris|privacy|security|deadlock|berkeley}
# highlights and searches change, but subsections and options are stable
foreach i {highlight options search manfill manref} {
# subsect
set manx($i-show-v) {"alwaysvis" "firstvis" "never"}
set manx($i-show-t) {"always" "at first" "never"}
}
set manx(openFilePWD) [pwd]
set man(randomscope) all
set manx(manhits) {}
set manx(highlight-show-v) {"halwaysvis" "firstvis" "never"}
set manx(search-show-v) {"salwaysvis" "sfirstvis" "never"}
set manx(manfill-show-v) {"malwaysvis" "mfirstvis" "never"}
set manx(show-atags) {alwaysvis halwaysvis salwaysvis malwaysvis}
set manx(show-ftags) {firstvis mfirstvis sfirstvis}
set manx(show-tags) [concat $manx(show-atags) $manx(show-ftags)]
set man(highlight-show) halwaysvis; #firstvis
#set man(subsect-show) never
set man(options-show) firstvis
set man(manref-show) never
set man(search-show) salwaysvis
set man(manfill-show) mfirstvis
#my .tkman: set man(manfill-sects) {description introduction "widget command" commands "interactive commands"}
set man(manfill-sects) {description introduction command}
#set man(outline-show) section; set manx(outline-show-v) [set manx(outline-show-t) {"chapter" "section" "subsection" "subsubsection"}]
# DON'T ADD THESE TO man(manfill-sects)
# environment - you consult to set once, then ignore
set man(manfill) "in entirety"; set manx(manfill-v) [set manx(manfill-t) {"in entirety" "as space"}]
set man(showsectmenu) 1; set manx(showsectmenu-v) {1 0}; set manx(showsectmenu-t) {"yes" "no"}
set man(rebus) 0; set manx(rebus-v) {1 0}; set manx(rebus-t) {"yes" "no"}
set man(showrandom) 0; set manx(showrandom-v) {1 0}; set manx(showrandom-t) {"yes" "no"}
set man(maxpage) 0; set manx(maxpage-v) {1 0}; set manx(maxpage-t) {"yes" "no"}
##always show highlights as combo +/-/menu
set man(geom) 570x800+150+10
set man(geom-prefs) +300+300
set man(iconname) {TkMan: $manx(name$w)}
#set man(iconbitmap) "" -- moved to Makefile
set man(iconbitmap) "(default)"
set man(iconmask) ""
set man(iconposition) ""
set man(startup) $env(HOME)/.tkman
# colors
set man(colors) {black white red "light yellow" yellow orange green blue beige SlateGray4 gray75 gray90}
# set preferred colors
set man(textfg) "black"
set man(textbg) "white"
#set man(buttfg) [set man(activefg) [set man(guifg) "gray"]]
#set man(buttbg) [set man(guibg) "beige"]
#set man(activebg) #eed5b7
# colors are Tk's defaults, except for black-on-white text
checkbutton .a
#set man(textfg) []
set man(buttfg) [set man(guifg) [.a cget -foreground]]
set man(guibg) [set man(buttbg) [.a cget -background]]
#set man(textbg) "white"; if {$man(textfg)=="white"} {set man(textbg) "black"}
# default textbg is ugly grey
set man(activefg) [.a cget -activeforeground]
set man(activebg) [.a cget -activebackground]
destroy .a
set man(selectionfg) black
set man(selectionbg) gray90
#set man(fontpixels) "X"
#set manx(fontpixels-v) {"-" "+"}; set manx(fontpixels-t) {"pixels" "points"}
set manx(dpi) [expr int([winfo screenwidth .]/([winfo screenmmwidth .]/25.4))]
## for intial setting, assume 75 and 100 dpi fonts available
##set man(fontpixels) [expr {($manx(dpi)==75 || $manx(dpi)==100)? "": "-"}]
# set interactively if no startup file
# find closest font dpi
if [catch {set bestdpi $env(DISPLAY_DPI)}] {
set bestdpi 75; set mindpidiff 1000
foreach dpi $manx(dpis) {
set dpidiff [expr abs($dpi-$manx(dpi))]
if {$dpidiff<$mindpidiff} {set mindipdiff $dpidiff; set bestdpi $dpi}
}
}
tk scaling [expr $bestdpi/72.0]
# tk scaling can be overridden in ~/.tkman free essay portion
# if you want to use pixels, use "tk scaling 1"
set manx(mono) [expr [winfo depth .]==1]
# [expr {[tk colormodel .]=="monochrome"}]
#set manx(mono) 1
if $manx(mono) {
set man(foreground) "black"
set man(background) "white"
set man(colors) {black white}
#set man(textfg) []
set man(activebg) [set man(buttfg) [set man(guifg) "black"]]
#set man(textbg) []
set man(activefg) [set man(buttbg) [set man(guibg) "white"]]
set man(selectionfg) $man(textbg); set man(selectionbg) $man(textfg); # gotta reverse on b&w
set man(search) [set man(isearch) "reverse"]
set man(cmd) underline
set man(highlight) "bold-italics"
set man(manref) "mono underline"
# set man(manrefseen) "mono"
set man(spot) reverse
# any more modifications for monochrome?
}
set man(highlight-meta) $man(highlight)
### collect all man's to this point as the defaults
# used for Defaults button in Preferences
# and to "comment out" unchanged parameters, so that subsequent
# changes (corrections), usually in the Makefile, propagate as expected
# (i.e., should make for fewer cases of "delete ~/.tkman")
# CAREFUL! Only man()'s recorded here in defaults are saved to ~/.tkman
# ok to put man() with modules, 'cause all modules loaded by this time
foreach i [array names man] {set default($i) $man($i)}
#
# man()-independent manx()
#
set manx(title) "TkMan"
regexp "..../../.." {$Date: 1998/02/12 00:16:44 $} manx(date)
set manx(date-seconds) [clock scan [string range $manx(date) 5 end]/[string range $manx(date) 0 3]]
# do this before any cd's
#set manx(mtimeargv0) [file mtime $argv0] -- NO! use RCS date string, above
set manx(expire-warnings) ""
if {[clock seconds] > [clock scan "1 year" -base $manx(date-seconds)]} {
set manx(expire-warnings) "This is a very old copy of TkMan. Please check ftp://ftp.cs.berkeley.edu/people/phelps/ucb/tcltk for the latest and greatest."
}
set manx(manList) $man(manList)
set manx(manTitleList) $man(manTitleList)
set manx(userconfig) "### your additions go below"
set manx(posnregexp) {([-+]?[0-9]+)([-+][0-9]+)}
set manx(bkupregexp) {(~|\.bak|\.old)}; # exclude old? may want to refer to it
set manx(init) 0
set manx(manDot) 0
set manx(cursor) left_ptr
set manx(yview,help) 1.0
set manx(paths) ""
set manx(pathstat) ""
set manx(uid) 1
set manx(hunkid) ""
set manx(outcnt) 1
set manx(debug) 0
set manx(defaults) 0
set manx(startup) $man(startup)
set manx(savegeom) 1
# can't be sure volume 1 exists(!)
#set manx(lastvol$w) 1
set manx(lastman) TkMan
set manx(censussortby) 1
set manx(highsortby) 0
set manx(normalize) "-N"
set manx(quit) 1
set manx(mandot) ""
set manx(db-manpath) ""
set manx(db-signature) ""
set manx(mondostats) 0
set manx(newmen) ""
set manx(highdontask) {}
#set manx(xmono) {courier|helvetica}
set manx(subdirs) "{man,cat}?*"
set manx(shift) 0
set manx(searchtime) 0
if [file executable /usr/ucb/whoami] {set manx(USER) [exec /usr/ucb/whoami]
} elseif [file executable /usr/bin/whoami] {set manx(USER) [exec /usr/bin/whoami]
} elseif [info exists manx(USER)] {set manx(USER) $env(USER)
} else {set manx(USER) "luser"}
#if [catch {set manx(USER) [exec /usr/ucb/whoami]}] {if [info exists manx(USER)] {set manx(USER) $env(USER)} else {set manx(USER) "luser"}}
append man(autosearch) "|$manx(USER)"; # vanity
# default printer
if [info exists env(PRINTER)] { set manx(printer) $env(PRINTER) } \
elseif [info exists env(LPDEST)] { set manx(printer) $env(LPDEST) } \
else { set manx(printer) "" }
# versions of supporting binaries, if those binaries happen to be used
set manx(bin-versregexp) "(\[0-9]+\\.\[0-9](\\.\[0-9]+)*)(\[^ ,;:\n\t]*)"
# Glimpse min version of 4.0 so know what index looks like for index pseudovolume
set manx(bin-versioned) {{rman "-v" 3.0.4} {glimpse "-V" 4.0} {glimpseindex "-V" 4.0}}
set manx(modes) {man texi rfc help section txt apropos glimpse info}
# tcl, java don't work well
# bug test: } -- should ignore closing brace
set manx(mode-desc) {"manual pages seen" "Texinfo files read" "RFC documents read" "references to help page" "volume listings invoked" "text files seen" "apropos listings" "Glimpse full-text searches" "ganders at this page"}
# "Tcl files browsed" "Java classes browsed"
DEBUG { assert [llength $manx(modes)]!=[llength $manx(mode-desc)] "mismatched modes lists" 1 }
set manx(stats) {man-hyper man-dups man-button man-link man-history man-shortcut man-random page-section page-highlight-go page-highlight-add page-highlight-sub page-shortcut-add page-shortcut-sub page-regexp-next page-regexp-prev page-incr-next page-incr-prev page-mono high-exact high-move high-lose high-carry print glimpse-builds outline-expand outline-collapse instantiation checkpoint}
set manx(stats-desc) {"via hyperlink" "via multiple matches pulldown" "via man button or typein box" "via links menu" "via history menu" "via shortcut menu" "via random page" "jumps to section header" "jump to highlight" "highlight additions" "highlight deletions" "shortcut additions" "shortcut deletions" "regular expression searches forward" "regular expression searches backward" "incremental searches forward" "incremental searches backward" "swaps between proportional font and monospaced" "exact" "repositioned" "lost" "pages printed" "Glimpse builds" "expanded outline" "collapsed outline" "additional instantiations" "checkpoints to save file"}
DEBUG { assert [llength $manx(stats)]!=[llength $manx(stats-desc)] "mismatched stats lists" 1 }
set stat(man-no) 0
set manx(all-stats) [concat $manx(modes) $manx(stats) "man-no" "executions"]
foreach i $manx(all-stats) {set stat(cur-$i) [set stat($i) 0]}
#source ~/spine/tkman/contrib/local-man.tcl
#set high(*) "format: time annotation made, start position and context, end position and context"
# TKMAN environment variable gives standard options
# env(TKMAN) goes first so options given on command-line override
if [info exists env(TKMAN)] {set argv "$env(TKMAN) $argv"}
if {![info exists env(PATH)] || $env(PATH)==""} { set env(PATH) "/usr/local/bin:/usr/bin" }
# don't pick up changes to env(PATH) in startup file (just so you know)
set manx(bin-paths) [split [string trim $env(PATH) ":"] ":"]
#puts "*** manParseCommandline"
# usually want to do this after startup file, but need to get -M here, before manx(startup) (?)
manParseCommandline
set manx(startup-short) [file tail $manx(startup)]
# execute some arbitrary Tcl code for new users (it may create a startup file)
if {![file exists $manx(startup)]} {eval $manx(newuser)}
# read in startup file after proc/vars/ui, so can modify them
set manx(savefilevers) "1.0"
set manx(updateinfo) ""
#puts "*** before startup"
# if on special case OS and don't have startup file, instantiate right startup code
# uname -s -r: SunOS 5.5 on ecstasy, IRIX 5.2 on bohr, SCO_SV on SCO OpenServer Release 5
# (for future references: OSF1 V3.2 on tumtum, HP-UX A.09.05 on euca)
# Put this code after eval newuser.
if {$manx(startup)!="" && ![file exists $manx(startup)] && [file writable [file dirname $manx(startup)]]} {
catch {
# set os [string tolower [exec uname -s]]; set osvers [exec uname -r]
set os [string tolower $tcl_platform(os)]; set osvers $tcl_platform(osVersion)
set setup ""; # most OSes work without configuration file
# only three trouble makers
if {$os=="sunos" && $osvers>=5.0} {
set setup solaris
if {$osvers>=5.6} {append setup "26"}
elseif {$osvers>=5.5} {append setup "25"}
} elseif {[string match "irix*" $os]} {
set setup irix
} elseif {$os=="sco_sv"} {
set setup $os
}
#puts stderr "\afound $setup"
if {$setup!="" && [info exists manx($setup-bindings)]} {
set fid [open $manx(startup) "w"]
puts $fid $manx($setup-bindings)
close $fid
}
}
}
if {$manx(startup)!="" && [file readable $manx(startup)]} {
set fid [open $manx(startup)]
# I don't know how this happens, but it has, apparently
if [string match "#!*" [gets $fid line]] {
puts stderr "$manx(startup) looks like an executable."
puts stderr "You should delete it, probably."
exit 1
}
while {![eof $fid]} {
# manx(savefilevers) discards alpha/beta designation
if {[regexp {^# TkMan v([0-9](\.[0-9])+)} $line all savefilevers]} {
set manx(savefilevers) $savefilevers
break
}
gets $fid line
}
catch {close $fid}
DEBUG {puts "*** savefilevers = $manx(savefilevers)"}
source $manx(startup)
#puts "*** read $manx(startup)"
# later use array {get,set}
# update several variables from old save files
set fixup 0
if {[package vcompare $manx(savefilevers) 1.6]==-1} {
set manx(updateinfo) "Startup file information updated from version $manx(savefilevers) to version $manx(version).\n"
### changes for < 1.6
# update these variables
foreach var {catsig compress zcat} {
# detailed list of changes more information than user wants
# append manx(updateinfo) " Changed man($var) from $man($var) to $default($var)\n"
set man($var) $default($var)
}
# zap problem shifted sb keys
foreach k {greater less question} {
set var "sb(key,MS-$k)"
if [info exists $var] {unset $var}
# append manx(updateinfo) " Deleted $k keybinding (use M-$k)\n"
}
# call manDot before user code
append manx(updatedinfo) " Added call to manDot\n"
# (if no problem before, no problem now)
# zap old man() variables ==> done every time save file updated
# foreach v [array names man] {
# if {![info exists default($v)] && ![string match "/*" $v]} {
# append manx(updateinfo) " Deleted obsolete variable man($v) (was set to $man($v))\n";
# unset man($v)
# }
# }
append manx(updateinfo) "Save updates via the Quit button or Occasionals/Checkpoint, or cancel updates via \"Occasionals / Quit, don't update\".\n"
# backup old startup file
if ![catch "file copy -force $manx(startup) [set ofn $manx(startup)-$manx(savefilevers)]"] {
append manx(updateinfo) "Old startup file saved as $ofn\n"
}
append manx(updateinfo) "\n\n"
set fixup 1
}
if {[package vcompare $manx(savefilevers) 1.8.1]==-1} {
if {[info exists man(stats)] && [llength [lsecond $man(stats)]]==2} {
# construct and save new version soon
set newstyle [lfirst $man(stats)]
foreach s [lrange $man(stats) 1 end] { lappend newstyle [lfirst $s] [lsecond $s] }
set man(stats) $newstyle
# use of glimpse has changed: -W, no -w for glimpse; -f for glimpseindex
set man(glimpse) $default(glimpse)
set man(glimpseindex) $default(glimpseindex)
# likewise, reset manformat so assured of picking up long lines
set man(format) $default(format)
set fixup 1
}
}
if {[package vcompare $manx(savefilevers) 2.0]==-1} {
foreach db [glob -nocomplain ~/.tkmandatabase*] {file delete -force -- $db}
}
# convert shortcuts to name+time added, the time for use later
if {[llength [lfirst $man(shortcuts)]]==1} {
set tmp {}
foreach i $man(shortcuts) {lappend tmp [list $i [clock seconds]]}
set man(shortcuts) $tmp
}
if {[info exists man(pagecnt)] && [llength [lsecond $man(pagecnt)]]==1} {
set tmp {}
foreach {name cnt lastread} $man(pagecnt) {lappend tmp $name [list $cnt $lastread]}
set man(pagecnt) $tmp
}
array set pagecnt $man(pagecnt)
if {!$manx(manDot)} {
#puts stderr "no mandot" -- clean this up silently
manDot
set fixup 1
}
if $fixup {after 500 manSave}
} else {
# if no startup file
}
#if {$man(fontpixels)=="X"} {
# set man(fontpixels) "+"
# after 100 {.__tk__messagebox.msg configure -font {Times 24}}
# if {[tkMessageBox -message "Is this font jagged?" -type yesno -icon question]=="yes"} {
# set man(fontpixels) "-"
# }
#}
if {$man(glimpse)==""} {set man(glimpseindex) ""}
set manx(shortcuts) {}
foreach i $man(shortcuts) {
foreach {name time} $i {lappend manx(shortcuts) $name; set short($name) $time}
}
catch {unset high(*)}
foreach {name info} $man(prof) {
set prof(cnt-$name) [lfirst $info]; set prof(totaltime-$name) [lsecond $info]
}
# manx(highs) needs to get latest list of colors
set manx(highs) [concat $manx(styles) reverse underline mono $man(colors)]
set manx(extravols) [list [list apropos "apropos hit list" [list "No apropos list" b]]]
if {$man(glimpse)!=""} {
lappend manx(extravols) [list glimpse "glimpse hit list" [list "No glimpse list" b]]
if {$man(indexglimpse)=="unified" && [file readable "$man(glimpsestrays)/.glimpse_index"]} {
lappend manx(extravols) [list "glimpseindex" "glimpse word index" {}]
}
}
lappend manx(extravols) {recent "Recently added/changed" {}} {high "All with Highlights" {}} {census "All pages seen" {}} {all "All Enabled Volumes" {}}
foreach i $manx(extravols) { lappend manx(specialvols) [lfirst $i] }
set manx(subregexp) {js(\.?([0-9]+))+}
set manx(supregexp) {js([0-9]+(\.[0-9]+)*)\.[0-9]+}
# calculate compression comparison expressions
set manx(zregexp) "\\.("
set manx(zglob) "{"
set manx(zoptglob) "{,"
foreach z $man(zlist) {
append manx(zregexp) "$z|"
append manx(zglob) "$z,"
append manx(zoptglob) ".$z,"
}
foreach z {zregexp zglob zoptglob} { set manx($z) [string trimright $manx($z) ",|"] }
append manx(zregexp) ")\$"
append manx(zglob) "}"
append manx(zoptglob) "}"
set manx(filetypes) [list [list "Manual Pages" ".\\\[1-9olnpD]*$manx(zoptglob)"] [list "Texinfo" ".texi$manx(zoptglob) .texinfo$manx(zoptglob)"] [list "Text file" ".txt$manx(zoptglob)"] {"Any file" *}]
# make master lists of man, bin dirs
set mani(MASTER,dirs) {}
foreach i $manx(mastermen) {
if {![file readable $i] || [lsearch $manx(paths) $i]!=-1} continue
#puts "master $i"; flush stdout
foreach j [glob -nocomplain $i/man*] {
if {[file readable $j] && [file isdirectory $j]} {lappend mani(MASTER,dirs) $j}
}
}
set manx(aux-binpaths) {}
foreach i $manx(masterbin) {
if {[lsearch $manx(bin-paths) $i]==-1 && [file readable $i] && [file isdirectory $i]} {
lappend manx(aux-binpaths)
}
}
# do this after source of ~/.tkman has chance to change some of these
set manx(binvars) {
manx(rman) man(glimpse) man(glimpseindex) man(cksum) man(gzgrep)
# man(co) man(rlog) man(rcsdiff) man(vdiff) -- don't check for these
man(format) man(print) man(catprint) man(apropos) man(zcat) man(compress)
}
after 1500 manBinCheck
# assertions
if {[llength $man(manList)]!=[llength $man(manTitleList)]} {
puts stderr "Length of section abbreviations differs from length of section titles:\n\nlength [llength $man(manList)]:\t$man(manList)\n\nlength [llength $man(manTitleList)]:\t$man(manTitleList)"
exit 1
}
# no sense to tease glimpseindex if can't write anything
set manx(glimpseindex) ""
if {$man(glimpse)!="" && $man(glimpseindex)!=""} {
foreach p $manx(paths) {
if {![file writable $p]} {set manx(glimpseindex) $man(glimpseindex); break}
}
}
# almost always you'll want to make the cross product
# if you don't, be tricky and `set manx(defaults) 1'
if !$manx(defaults) manDescDefaults
# set up cumulative statistics watchdog
lappend man(chronobrowse) "X"
set manx(statsdirty) 0
manStatsSet
# added this statistic after the others
#if {[package vcompare $manx(savefilevers) 2.0.3]==-1} {set stat(cum-executions) [expr $stat(cum-executions)/$stat(cum-help)]; set man(stats) "executions $stat(cum-executions) $man(stats)"}
if {[package vcompare $manx(savefilevers) 2.0.3]==-1} {set stat(cum-executions) $stat(cum-help); set man(stats) "executions $stat(cum-executions) $man(stats)"}
#if {$stat(cum-executions)==0 && $stat(cum-help)>0} {set stat(cum-executions) $stat(cum-help)}
manStatsSaveFile; # should just set timer this time through, not save to a file
# if no stray dirs for glimpse, don't glimpse there
#if {$man(indexglimpse)=="distributed" && [llength $mani($manx(glimpsestrays),dirs)]==0} {set manx(glimpsestrays) ""}
if 0 {
foreach proc [info procs man*] {
puts -nonewline "rewriting $proc"
set vals ""; foreach aargh [info args $proc] {append vals " \$$aargh"}
set aarghs {}
foreach aargh [info args $proc] { if [info default $proc $aargh def] {lappend aarghs [list $aargh $def]} else {lappend aarghs $aargh}}
puts " $aarghs"
proc $proc $aarghs "puts \"entering $proc $vals\"; flush stdout\n[info body $proc]\nputs {exiting $proc}; flush stdout"
}
}
set STOP 0
# 8.0, plus sizes for pulldown?
eval font create textpro [spec2font $man(text-family) $man(text-style) $man(text-points)]
eval font create gui [spec2font $man(gui-family) $man(gui-style) $man(gui-points)]
eval font create guisymbol [spec2font "symbol" $man(gui-style) $man(gui-points)]
eval font create guimono [spec2font "courier" $man(gui-style) $man(gui-points)]
eval font create peek [spec2font $man(text-family) "italics" $man(text-points) "s"]
eval font create textmono [spec2font "Courier" $man(text-style) $man(text-points)]
option add Tkman*font gui 61
#foreach f {diffa diffc diffd} {
# eval font create $f [spec2font $man($f-family) $man($f-style) $man(text-points)]
#}
TkMan
#image create bitmap wmicon -data [icon cget -data]
set starttime [time manInit]
DEBUG {
puts stdout "init takes $starttime"
# convenience variables
# set w .man
set t $w.show
# debug box
entry $w.in -relief sunken -textvariable manx(debugcmd)
bind $w.in <KeyPress-Return> {manWinstdout .man "[eval $manx(debugcmd)]"}
pack $w.in -fill x
proc manStatsSaveFile args {}
}
manHighlightsUpdate
set stat(executions) 1
# no profiling on non-TkMan procs
#rename proc {}
#rename proc_builtin proc
if {$stat(cum-executions)==100
|| ($stat(cum-executions)>0 && int($stat(cum-executions)/1000)*1000==$stat(cum-executions))} {
set txt "This is the $stat(cum-executions)th time you've run TkMan. Please help improve future versions of TkMan by emailing the statistics collected in the file ~/.tkman to phelps@ACM.org. (This must be done manually; no action is taken automatically.) Thanks!"
manTextPlug $w.show 1.0 "$txt\n\n" b
tk_messageBox -icon info -parent $w -title "Please Help" -type ok -message $txt
}
|