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
|
##########################################################################
# REPORT.TCL, output handling procedures
# Copyright (C) 2002-2004 Mark Lakata
# Copyright (C) 2004-2017 Kent Mein
# Copyright (C) 2016-2025 Xavier Delaruelle
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
#
# Debug, Info, Warnings and Error message handling.
#
# save message when report is not currently initialized as we do not
# know yet if debug mode is enabled or not
proc reportDebug {message {caller _undef_}} {
set caller [getCallingProcName]
lappend ::errreport_buffer [list reportDebug $message $caller]
}
# regular procedure to use once error report is initialized
proc __reportDebug {message {caller _undef_}} {
# display active interp details if not the main one
set prefix [currentState debug_msg_prefix]
if {$caller eq {_undef_}} {
set caller [getCallingProcName]
}
# display caller name as prefix
if {$caller ne {}} {
append prefix "$caller: "
}
report [sgr db "DEBUG $prefix$message"] 0 1
}
# alternative procedure used when debug is disabled
proc __reportDebugNop {message {caller _undef_}} {}
proc reportWarning {message} {
reportError $message WARNING wa 0
}
proc reportError {message {severity ERROR} {sgrkey er} {incr_count 1}} {
lappend ::errreport_buffer [list reportError $message $severity $sgrkey\
$incr_count]
}
proc __reportError {message {severity ERROR} {sgrkey er} {incr_count 1}} {
# if report disabled, also disable error raise to get a coherent behavior
# (if no message printed, no error code change). also no report if no msg
if {![getState inhibit_errreport] && [string length $message]} {
if {$incr_count} {
incrErrorCount
}
set msgsgr "[sgr $sgrkey $severity]: $message"
# record message to report it later on if a record id is found
if {[currentState msgrecordid] ne {}} {
recordMessage $msgsgr
# skip message report if silent
} elseif {[isVerbosityLevel concise]} {
# save error messages to render them all together in JSON format
if {[isStateEqual report_format json]} {
lappend ::g_report_erralist $severity $message
} else {
report $msgsgr 0 0 1
}
}
}
}
# throw known error (call error with 'known error' code)
proc knerror {message {code MODULES_ERR_KNOWN}} {
error $message {} $code
}
proc knerrorOrWarningIfForced {message {code MODULES_ERR_KNOWN}} {
if {[getState force]} {
reportWarning $message
} else {
knerror $message $code
}
}
# save message if report is not yet initialized
proc reportErrorAndExit {message} {
lappend ::errreport_buffer [list reportErrorAndExit $message]
}
# regular procedure to use once error report is initialized
proc __reportErrorAndExit {message} {
incrErrorCount
renderFalse
error $message {} MODULES_ERR_RENDERED
}
proc reportErrorOrWarningIfForced {message} {
if {[getState force]} {
reportWarning $message
} else {
reportError $message
}
}
proc reportInternalBug {message {modfile {}} {title {Module ERROR}}} {
reportError [formatInternalBugMsg $message $modfile] $title me
}
proc reportInternalBugWarning {message {modfile {}} {title {Module\
WARNING}}} {
reportError [formatInternalBugMsg $message $modfile] $title wa 0
}
proc reportInternalBugOrWarningIfForced {message {modfile {}}} {
if {[getState force]} {
reportInternalBugWarning $message $modfile
} else {
reportInternalBug $message $modfile
}
}
proc formatInternalBugMsg {message modfile} {
if {$modfile ne {}} {
set message [formatMessageInModule $message $modfile]
}
return "$message\nPlease contact <[getConf contact]>"
}
proc formatMessageInModule {message modfile} {
return "$message\nIn '$modfile'"
}
proc reportInfo {message {title INFO}} {
if {[isVerbosityLevel normal]} {
# use reportError for convenience but there is no error here
reportError $message $title in 0
}
}
proc reportTrace {message {title TRACE}} {
if {[isVerbosityLevel trace]} {
# use reportError for convenience but there is no error here
reportError [sgr tr $message] $title tr 0
}
}
proc reportTimer {message timestr start_us stop_us} {
set elapsed_ms [expr {($stop_us - $start_us) / 1000.0}]
report [sgr db "TIMER $message [format $timestr $elapsed_ms]"] 0 1
}
# trace procedure execution start
proc reportTraceExecEnter {cmdstring op} {
reportDebug $cmdstring [getCallingProcName]
}
# time procedure execution duration
proc reportTimerExecEnter {cmdstring op} {
uplevel 1 set proc_timer_start [clock microseconds]
}
proc reportTimerExecLeave {cmdstring code result op} {
reportTimer $cmdstring {(%.3f ms)} [uplevel 1 set proc_timer_start]\
[clock microseconds]
}
# record messages on the eventual additional module evaluations that have
# occurred during the current evaluation
proc reportModuleEval {} {
set evalid [currentState evalid]
array set contexttitle {conun {Unloading conflict} reqlo {Loading\
requirement} depre {Reloading dependent} depun {Unloading dependent}\
urequn {Unloading useless requirement}}
if {[info exists ::g_moduleEval($evalid)]} {
foreach contextevallist $::g_moduleEval($evalid) {
set msgrecidlist [lassign $contextevallist context]
# skip context with no description title
if {[info exists contexttitle($context)]} {
# exclude hidden modules from report unless an high level of
# verbosity is set
if {[info exists ::g_moduleHiddenEval($evalid:$context)] &&\
![isVerbosityLevel verbose2]} {
lassign [getDiffBetweenList $msgrecidlist\
$::g_moduleHiddenEval($evalid:$context)] msgrecidlist
}
if {[llength $msgrecidlist]} {
set moddesiglist {}
foreach msgrecid $msgrecidlist {
lappend moddesiglist [getModuleDesignation $msgrecid]
}
reportInfo [join $moddesiglist] $contexttitle($context)
}
}
}
# purge list in case same evaluation is re-done afterward
unset ::g_moduleEval($evalid)
}
}
# render messages related to current record id under an header block
proc reportMsgRecord {header {hidden 0}} {
set recid [currentState msgrecordid]
if {[info exists ::g_msgRecord($recid)]} {
# skip message report if silent (report even if hidden as soon as msgs
# are associated to hidden module evaluation)
if {[isVerbosityLevel concise]} {
set tty_cols [getState term_columns]
set padding { }
set dispmsg $header
foreach msg $::g_msgRecord($recid) {
# split lines if too large for terminal
set first 1
set max_idx [tcl::mathfunc::max [expr {$tty_cols - [string length\
$padding]}] 1]
set linelist [list]
foreach line [split $msg \n] {
set lineadd {}
while {$lineadd ne $line} {
set line_max_idx $max_idx
# sgr tags consume no length
set eidx 0
while {[set sidx [string first "\033\[" $line $eidx]] !=\
-1} {
set eidx [string first m $line $sidx]
incr line_max_idx [expr {1 + $eidx - $sidx}]
}
# no split if no whitespace found to slice
if {[string length $line] > $line_max_idx && [set cut_idx\
[string last { } $line $line_max_idx]] != -1} {
set lineadd [string range $line 0 $cut_idx-1]
set line [string range $line $cut_idx+1 end]
} else {
set lineadd $line
}
# skip empty line
if {[string trim $lineadd] ne {}} {
lappend linelist $lineadd
}
if {$first} {
set first 0
incr max_idx -[string length $padding]
if {$max_idx < 1} {set max_idx 1}
}
}
}
# display each line
set first 1
foreach line $linelist {
append dispmsg \n
if {$first} {
set first 0
} else {
append dispmsg $padding
}
append dispmsg $padding$line
}
}
reportSeparateNextContent
report $dispmsg
reportSeparateNextContent
}
# purge message list in case same evaluation is re-done afterward
unset ::g_msgRecord($recid)
# report header if no other specific msg to output in verbose mode or in
# normal verbosity mode if currently processing a cmd which triggers
# multiple module evaluations that cannot be guessed by the user (excluding
# dependency evaluations which are reported by triggering top evaluation)
# if hidden flag is enabled report only if verbosity >= verbose2
} elseif {(!$hidden && ([isVerbosityLevel verbose] || ([isVerbosityLevel\
normal] && ([ongoingCommandName restore] || [ongoingCommandName source]\
|| [ongoingCommandName reset] || [ongoingCommandName stash] ||\
[ongoingCommandName stashpop] || [ongoingCommandName cacheclear] ||\
[ongoingCommandName cachebuild]) && $recid eq [topState msgrecordid])))\
|| ($hidden && [isVerbosityLevel verbose2])} {
report $header
}
}
# separate next content produced if any
proc reportSeparateNextContent {} {
lappend ::errreport_buffer [list reportSeparateNextContent]
}
# regular procedure to use once error report is initialized
proc __reportSeparateNextContent {} {
# hold or apply
if {[depthState reportholdid] > 0} {
lappend ::g_holdReport([currentState reportholdid]) [list\
reportSeparateNextContent]
} else {
setState report_sep_next 1
}
}
# save message for block rendering
proc recordMessage {message} {
set recid [currentState msgrecordid]
if {$recid eq [currentState reportholdrecid]} {
lappend ::g_holdReport([currentState reportholdid]) [list\
recordMessage $message]
} else {
lappend ::g_msgRecord($recid) $message
}
}
# check if some msg have been recorded for current evaluation
proc isMsgRecorded {} {
return [info exists ::g_msgRecord([currentState msgrecordid])]
}
# filter and format error stack trace to only report useful content
proc formatErrStackTrace {errmsg loc {cmdlist {}}} {
set headstr "\n while executing\n"
set splitstr "\n invoked from within\n"
set splitstrlen [string length $splitstr]
set aftheadidx [string first $headstr $errmsg]
if {$aftheadidx != -1} {
incr aftheadidx [string length $headstr]
}
# get name of invalid command name to maintain it in error stack trace
if {[string equal -length 22 {invalid command name "} $errmsg]} {
set unkcmd [lindex [split [string range $errmsg 0 $aftheadidx] {"}] 1]
} else {
set unkcmd {}
}
# get list of modulecmd.tcl internal procedure to filter out from stack
# also add the way subcmds are launched through module proc ($cmdprocname)
# skip this when no interp command list is provided
if {[llength $cmdlist]} {
lassign [getDiffBetweenList [list {*}[info commands] {*}[info procs]\
{$cmdprocname}] $cmdlist] filtercmdlist keepcmdlist
} else {
set filtercmdlist {}
}
# define commands to filter out from bottom of stack
set filtercmdendlist [list {eval [getModuleContent\
$::ModulesCurrentModulefile]} "source $loc" {uplevel 1 source\
$siteconfig} {eval $cachecontent}]
# define commands to filter out from middle of stack
set filtercmdmidlist [list {interp eval $itrp $::source_cache($filename)}]
# filter out modulecmd internal references at beginning of stack
set internals 1
while {$internals && $aftheadidx != -1} {
# fetch erroneous command and its caller
set stackelt [string range $errmsg $aftheadidx [string first\
$splitstr $errmsg $aftheadidx]]
lassign [split [lindex [split $stackelt {"}] 1]] cmd1 cmd2
set cmdcaller [lindex [split [string range $stackelt [string last\
{(procedure } $stackelt] end] {"}] 1]
if {$cmd1 eq {eval}} {
set cmd1 $cmd2
}
# filter out stack element referring to or called by an unknown
# procedure (ie. a modulecmd.tcl internal procedure)
if {$cmd1 ne $unkcmd && ($cmdcaller in $filtercmdlist || $cmd1 in\
$filtercmdlist)} {
set errmsg [string replace $errmsg $aftheadidx [expr {[string first\
$splitstr $errmsg] + $splitstrlen - 1}]]
} else {
set internals 0
}
}
# filter out modulecmd internal references at end of stack
set internals 1
while {$internals} {
set beffootidx [string last $splitstr $errmsg]
set stackelt [string range $errmsg $beffootidx end]
set cmd [lindex [split $stackelt {"}] 1]
if {$cmd in $filtercmdendlist} {
set errmsg [string replace $errmsg $beffootidx end]
} else {
set internals 0
}
}
# filter out modulecmd internal references in middle of stack
foreach filtercmdmid $filtercmdmidlist {
set filterstartidx [string first \"$filtercmdmid\" $errmsg]
if {$filterstartidx != -1} {
set filterendidx [expr {[string first $splitstr $errmsg\
$filterstartidx] + [string length $splitstr] - 1}]
set errmsg [string replace $errmsg $filterstartidx $filterendidx]
}
}
# replace error location at end of stack
set lastnl [string last \n $errmsg]
set lastline [string range $errmsg $lastnl+1 end]
if {[string match { ("eval" body line*} $lastline]} {
set errmsg [string replace $errmsg $lastnl $lastnl+[string length\
" (\"eval\" body line"] "\n (file \"$loc\" line"]
} elseif {![string match { (file *} $lastline]} {
# add error location at end of stack
append errmsg "\n (file \"$loc\")"
}
return $errmsg
}
# Test if color is enabled and passed sgrkey is defined and not null
proc isSgrkeyColored {sgrkey} {
return [expr {[getConf color] && [info exists ::g_colors($sgrkey)] &&\
$::g_colors($sgrkey) ne {}}]
}
# Select Graphic Rendition of a string with passed sgr keys (if color enabled)
proc sgr {keylist str {himatchmap {}} {othkeylist {}}} {
if {[getConf color]} {
set sgrreset 22
foreach sgrkey $keylist {
if {[info exists ::g_colors($sgrkey)]} {
# track color key that have been used
if {![info exists ::g_used_colors($sgrkey)]} {
set ::g_used_colors($sgrkey) 1
}
if {[info exists sgrset]} {
append sgrset {;}
}
append sgrset $::g_colors($sgrkey)
# if render bold or faint just reset that attribute, not all
if {$sgrreset != 0 && $sgrset != 1 && $sgrset != 2} {
set sgrreset 0
}
}
}
if {![llength $othkeylist]} {
# highlight matching substring
if {[llength $himatchmap]} {
set str [string map $himatchmap $str]
}
if {[info exists sgrset]} {
set str "\033\[${sgrset}m$str\033\[${sgrreset}m"
}
} else {
if {![info exists sgrset]} {
set sgrset {}
} else {
append sgrset {;}
}
# determine each chunk where the other sgr keys apply
set tagsgrlen [expr {int(ceil([string length $str]/[llength\
$othkeylist]))}]
for {set i 0} {$i < [llength $othkeylist]} {incr i} {
set idx [expr {$i*$tagsgrlen}]
set sgrkey [lindex $othkeylist $i]
lappend sgridxlist $idx $::g_colors($sgrkey)
# track color key that have been used
if {![info exists ::g_used_colors($sgrkey)]} {
set ::g_used_colors($sgrkey) 1
}
}
# determine each chunk where the highlight applies
set hiidxlist {}
foreach {mstr sgrmstr} $himatchmap {
set idx 0
while {$idx != -1} {
if {[set idx [string first $mstr $str $idx]] != -1} {
lappend hiidxlist $idx
incr idx [string length $mstr]
# add highlight end index unless if end of string
if {$idx < [string length $str]} {
lappend hiidxlist $idx
}
}
}
# no need to look at next match string if this one was found
if {[llength $hiidxlist]} {
break
}
}
# mix other sgr chunks with highlighted chunks to define sgr codes
set i 0
set j 0
set sgridx [lindex $sgridxlist 0]
set hiidx [lindex $hiidxlist 0]
set hicur 0
set sgrcur {}
set sgrrst {0;}
while {$i < [llength $sgridxlist] || $j < [llength $hiidxlist]} {
set sgrcode {}
set cursgridx $sgridx
# sgr chunk change
if {$sgridx ne {} && ($hiidx eq {} || $sgridx <= $hiidx)} {
incr i
set sgrcur $sgrset[lindex $sgridxlist $i]
set idx $sgridx
if {$idx != 0} {
append sgrcode $sgrrst
}
append sgrcode $sgrcur
incr i
set sgridx [lindex $sgridxlist $i]
}
# highlight change
if {$hiidx ne {} && ($cursgridx eq {} || $hiidx <= $cursgridx)} {
set idx $hiidx
set hicur [expr {!$hicur}]
if {$hicur} {
if {$sgrcode ne {}} {
append sgrcode {;}
}
append sgrcode $::g_colors(hi)
# restore current sgr set to only clear highlight
} elseif {$sgrcode eq {}} {
append sgrcode $sgrrst $sgrcur
}
incr j
set hiidx [lindex $hiidxlist $j]
} elseif {$hicur} {
append sgrcode {;} $::g_colors(hi)
}
lappend fullsgridxlist $idx $sgrcode
}
# reset sgr at end of string
lappend fullsgridxlist [string length $str] 0
# apply defined sgr codes to the string
set stridx 0
foreach {sgridx sgrcode} $fullsgridxlist {
if {$sgridx != 0} {
append sgrstr [string range $str $stridx $sgridx-1]
}
append sgrstr "\033\[${sgrcode}m"
set stridx $sgridx
}
set str $sgrstr
}
}
return $str
}
# Sort tags to return those matching defined sgr keys in a list up to a given
# maxnb number and if tag not set to be displayed by its name. Other elements
# are returned in a separate list
proc getTagSgrForModname {keylist maxnb} {
set sgrkeylist {}
if {[getConf color]} {
set otherlist {}
foreach key $keylist {
if {[info exists ::g_colors($key)] && ![info exists\
::g_tagColorName($key)] && [llength $sgrkeylist] < $maxnb} {
lappend sgrkeylist $key
} else {
lappend otherlist $key
}
}
} else {
set otherlist $keylist
}
return [list $sgrkeylist $otherlist]
}
# save message if report is not yet initialized
proc report {message {nonewline 0} {immed 0} {padnl 0}} {
lappend ::errreport_buffer [list report $message $nonewline $immed $padnl]
}
# regular procedure to use once error report is initialized
proc __report {message {nonewline 0} {immed 0} {padnl 0}} {
# hold or print output
if {!$immed && [depthState reportholdid] > 0} {
lappend ::g_holdReport([currentState reportholdid]) [list report\
$message $nonewline $immed $padnl]
} else {
# produce blank line prior message if asked to
if {[isStateDefined reportfd] && [isStateDefined report_sep_next]} {
unsetState report_sep_next
report [expr {[isStateEqual report_format json] ? {,} : {}}]
}
# prefix msg lines after first one with 2 spaces
if {$padnl} {
set first 1
foreach line [split $message \n] {
if {$first} {
set first 0
} else {
append padmsg "\n "
}
append padmsg $line
}
set message $padmsg
}
# protect from issue with fd, just ignore it
catch {
if {$nonewline} {
puts -nonewline [getState reportfd] $message
} else {
puts [getState reportfd] $message
}
}
}
}
# report error the correct way depending of its type
proc reportIssue {issuetype issuemsg {issuefile {}}} {
switch -- $issuetype {
invalid {
reportInternalBug $issuemsg $issuefile
}
default {
reportError $issuemsg
}
}
}
# report defined command (used in display evaluation mode)
proc reportCmd {cmd args} {
# use Tcl native string representation of list
if {$cmd eq {-nativeargrep}} {
set cmd [lindex $args 0]
set cmdargs [lrange $args 1 end]
} else {
set cmdargs [listTo tcl $args 0]
}
set extratab [expr {[string length $cmd] < 8 ? "\t" : {}}]
report [sgr cm $cmd]$extratab\t$cmdargs
# empty string returns if command result is another command input
return {}
}
# report defined command (called as an execution trace)
proc reportCmdTrace {cmdstring args} {
reportCmd {*}$cmdstring
}
proc reportVersion {} {
report {Modules Release @MODULES_RELEASE@@MODULES_BUILD@\
(@MODULES_BUILD_DATE@)}
}
proc reportName {} {
report Modules
}
# disable error reporting (non-critical report only) unless debug enabled
proc inhibitErrorReport {} {
if {![isVerbosityLevel trace]} {
setState inhibit_errreport 1
}
}
proc initProcReportTrace {type prc} {
##nagelfar ignore #7 Non static subcommand
if {[isVerbosityLevel debug] && [getState timer]} {
# time execution of procedure instead of regular debug report
trace $type execution $prc enter reportTimerExecEnter
trace $type execution $prc leave reportTimerExecLeave
} elseif {[isVerbosityLevel debug2]} {
# trace each procedure call
trace $type execution $prc enter reportTraceExecEnter
}
}
# init error report and output buffered messages
proc initErrorReport {} {
# ensure init is done only once
if {![isStateDefined init_error_report]} {
setState init_error_report 1
# ask for color init now as debug mode has already fire lines to render
# and we want them to be reported first (not the color init lines)
if {[isVerbosityLevel debug]} {
getConf color
}
# trigger pager start if something needs to be printed, to guaranty
# reportDebug calls during pager start are processed in buffer mode
if {[isVerbosityLevel debug]} {
getState reportfd
}
# only report timing information in debug mode if timer mode is enabled
if {[isVerbosityLevel debug] && ![getState timer]} {
# replace report procedures used to buffer messages until error
# report being initialized by regular report procedures
# delete initial reportDebug proc after getState which needs it
rename ::reportDebug {}
rename ::__reportDebug ::reportDebug
} else {
rename ::reportDebug {}
# set a disabled version if debug is disabled
rename ::__reportDebugNop ::reportDebug
}
rename ::reportError {}
rename ::__reportError ::reportError
rename ::reportErrorAndExit {}
rename ::__reportErrorAndExit ::reportErrorAndExit
rename ::reportSeparateNextContent {}
rename ::__reportSeparateNextContent ::reportSeparateNextContent
rename ::report {}
rename ::__report ::report
# setup traces for either debug or timer reports
if {[isVerbosityLevel debug] && [getState timer] || [isVerbosityLevel\
debug2]} {
# list of core procedures to exclude from tracing
set excl_prc_list [list report reportDebug reportFlush reportTimer\
reportTraceExecEnter reportTimerExecEnter reportTimerExecLeave\
initProcReportTrace isVerbosityLevel reportSeparateNextContent\
getState setState unsetState lappendState lpopState currentState\
depthState isStateDefined isStateEqual sgr getConf setConf\
unsetConf lappendConf getCallingProcName isEnvVarDefined\
envVarEquals log getConfList]
foreach prc [info procs] {
if {$prc ni $excl_prc_list} {
initProcReportTrace add $prc
}
}
}
# now error report is init output every message saved in buffer; first
# message will trigger message paging configuration and startup unless
# already done if debug mode enabled
foreach errreport $::errreport_buffer {
{*}$errreport
}
}
}
# drop or report held messages
proc releaseHeldReport {args} {
foreach {holdid action} $args {
if {[info exists ::g_holdReport($holdid)]} {
if {$action eq {report}} {
foreach repcall $::g_holdReport($holdid) {
{*}$repcall
}
}
unset ::g_holdReport($holdid)
}
# also drop reported tag of conflict error
if {[info exists ::g_holdReportConflict($holdid)]} {
if {$action eq {drop}} {
foreach {evalid drop_mod_list} $::g_holdReportConflict($holdid) {
lassign [getDiffBetweenList $::report_conflict($evalid)\
$drop_mod_list] ::report_conflict($evalid)
}
}
unset ::g_holdReportConflict($holdid)
}
# also drop failed module evaluation to get their failure information
# if later retried
if {[info exists ::g_holdModuleFailedEval($holdid)]} {
if {$action eq {drop}} {
foreach {evalid failed_context failed_mod}\
$::g_holdModuleFailedEval($holdid) {
set failed_eval_list $::g_moduleFailedEval($evalid)
for {set i 0} {$i < [llength $failed_eval_list]} {incr i} {
if {[lindex $failed_eval_list $i] eq $failed_context &&\
[lindex $failed_eval_list $i+1] eq $failed_mod} {
set failed_eval_list [lreplace $failed_eval_list $i $i+1]
break
}
}
set ::g_moduleFailedEval($evalid) $failed_eval_list
}
}
unset ::g_holdModuleFailedEval($holdid)
}
}
}
# final message output and reportfd flush and close
proc reportFlush {} {
# report execution time if asked
if {[getState timer]} {
reportSeparateNextContent
reportTimer {Total execution took} {%.3f ms} $::timer_start [clock\
microseconds]
}
# finish output document if json format enabled
if {[isStateEqual report_format json]} {
# render error messages all together
if {[info exists ::g_report_erralist]} {
# ignite report first to get eventual error message from report
# initialization in order 'foreach' got all messages prior firing
report "\"errors\": \[" 1
foreach {sev msg} $::g_report_erralist {
# split message in lines
lappend dispmsglist "\n{ \"severity\": \"$sev\", \"message\": \[\
\"[join [split [charEscaped $msg \"] \n] {", "}]\" \] }"
}
report "[join $dispmsglist ,] \]"
}
# inhibit next content separator if output is ending
unsetState report_sep_next
report \}
}
# close pager if enabled
if {[isStateDefined reportfd] && ![isStateEqual reportfd stderr]} {
catch {flush [getState reportfd]}
catch {close [getState reportfd]}
}
}
proc logEvent {event args} {
if {$event in [getConfList logged_events]} {
set log_info_list [list user [getState username] {*}$args]
set log_formatted_list {}
foreach {key val} $log_info_list {
lappend log_formatted_list "$key=\"$val\""
}
set log_message [join $log_formatted_list]
log $log_message
}
}
proc log {log_message} {
lappend ::g_log_msg_list $log_message
}
# send messages to log
proc logFlush {} {
# logger pipe is started only if enabled and some msgs need to be logged
set logfd [getState logfd]
# logging only occurs from this procedure with is run during termination
if {[string length $logfd]} {
if {[catch {
foreach log_msg $::g_log_msg_list {
puts $logfd $log_msg
}
flush $logfd
close $logfd
} errMsg]} {
reportWarning {Issue occurred when logging information}
}
}
}
# check if element passed as argument (corresponding to a kind of information)
# should be part of output content
proc isEltInReport {elt {retifnotdef 1}} {
# get config name relative to current sub-command and output format
set conf [currentState commandname]
if {[getState report_format] ne {regular}} {
append conf _[getState report_format]
}
append conf _output
set arrname ::g_$conf
##nagelfar vartype arrname varName
if {[info exists ::g_config_defs($conf)]} {
# build value cache if it does not exist yet
if {![array exists $arrname]} {
array set $arrname {}
foreach confelt [getConfList $conf] {
##nagelfar ignore Suspicious variable name
set ${arrname}($confelt) 1
}
}
# check if elt is marked to be included in output
##nagelfar ignore Suspicious variable name
return [info exists ${arrname}($elt)]
} else {
# return $retifnotdef (ok by default) in case no config option
# corresponds to the current module sub-command and output format
return $retifnotdef
}
}
proc registerModuleDesignation {evalid mod vrlist taglist} {
set ::g_moduleDesgination($evalid) [list $mod $vrlist $taglist]
}
proc getModuleFromEvalId {evalid} {
if {[info exists ::g_moduleDesgination($evalid)]} {
return [lindex $::g_moduleDesgination($evalid) 0]
}
}
proc getModuleDesignation {from {mod {}} {sgr 1}} {
# fetch module name version and variants from specified context
switch -- $from {
spec {
set moddesig [getModuleNameAndVersFromVersSpec $mod]
set vrlist [getVariantList $mod 7 0 1]
set taglist {}
}
loaded {
set moddesig $mod
set vrlist [getVariantList $mod 7]
set taglist {}
}
default {
# fetch information from passed evaluation id
if {[info exists ::g_moduleDesgination($from)]} {
lassign $::g_moduleDesgination($from) moddesig vrlist taglist
# if not found, use passed spec to compute designation
} else {
set moddesig [getModuleNameAndVersFromVersSpec $mod]
set vrlist [getVariantList $mod 7 0 1]
set taglist [getExportTagList $mod]
}
}
}
# build module designation
switch -- $sgr {
2 {
set vrsgr va
set himatchmap [prepareMapToHightlightSubstr $moddesig]
set showtags 1
# prepare list of tag abbreviations that can be substituted and list
# of tags whose name should be colored
getConf tag_abbrev
getConf tag_color_name
# abbreviate tags
set taglist [abbrevTagList $taglist]
}
1 {
set vrsgr {se va}
set himatchmap {}
set showtags 0
}
0 {
set vrsgr {}
set himatchmap {}
set showtags 0
}
}
lassign [formatListEltToDisplay $moddesig {} {} {} {} 0 0 $taglist\
$showtags $vrlist $vrsgr 1 $himatchmap] disp dispsgr displen
return $dispsgr
}
#
# Helper procedures to format various messages
#
proc getHintUnFirstMsg {modlist} {
return "HINT: Might try \"module unload [join $modlist]\" first."
}
proc getHintLoFirstMsg {modlist} {
if {[llength $modlist] > 1} {
set oneof {at least one of }
set mod modules
} else {
set oneof {}
set mod module
}
return "HINT: ${oneof}the following $mod must be loaded first: [join\
$modlist]"
}
proc getErrConflictMsg {conlist} {
return "Module cannot be loaded due to a conflict.\n[getHintUnFirstMsg\
$conlist]"
}
proc getErrPrereqMsg {prelist {load 1} {is_path_specific 0}} {
if {$load} {
foreach pre $prelist {
lappend predesiglist [getModuleDesignation spec $pre]
}
lassign [list {} missing [getHintLoFirstMsg $predesiglist]] un miss\
hintmsg
} else {
##nagelfar ignore Found constant
lassign [list un a [getHintUnFirstMsg $prelist]] un miss hintmsg
}
set path_specific_msg [expr {$is_path_specific ? [getSpecificPathMsg] :\
{}}]
return "Module cannot be ${un}loaded due to $miss\
prereq$path_specific_msg.\n$hintmsg"
}
proc getErrReqLoMsg {prelist {is_path_specific 0}} {
foreach pre $prelist {
lappend predesiglist [getModuleDesignation spec $pre]
}
set path_specific_msg [expr {$is_path_specific ? [getSpecificPathMsg] :\
{}}]
return "Load of requirement [join $predesiglist { or }]$path_specific_msg\
failed"
}
proc getReqNotLoadedMsg {prelist {is_path_specific 0}} {
foreach pre $prelist {
lappend predesiglist [getModuleDesignation spec $pre]
}
set path_specific_msg [expr {$is_path_specific ? [getSpecificPathMsg] :\
{}}]
return "Requirement [join $predesiglist { or }]$path_specific_msg is not\
loaded"
}
proc getSpecificPathMsg {} {
return { (specific path)}
}
proc getKindModuleBeStateMsg {kind mod_list state} {
set is [expr {[llength $mod_list] > 1 ? {are} : {is}}]
foreach mod $mod_list {
lappend mod_desig_list [getModuleDesignation loaded $mod]
}
return "$kind [join $mod_desig_list { and }] $is $state"
}
proc getDepLoadedMsg {pre_mod_list} {
return [getKindModuleBeStateMsg Dependent $pre_mod_list loaded]
}
proc getDepLoadingMsg {pre_mod_list} {
return [getKindModuleBeStateMsg Dependent $pre_mod_list loading]
}
proc getErrConUnMsg {conlist} {
set condesiglist {}
foreach con $conlist {
lappend condesiglist [getModuleDesignation spec $con]
}
return "Unload of conflicting [join $condesiglist { and }] failed"
}
proc getConLoadedMsg {con_mod_list} {
return [getKindModuleBeStateMsg Conflicting $con_mod_list loaded]
}
proc getConLoadingMsg {con_mod_list} {
return [getKindModuleBeStateMsg Conflicting $con_mod_list loading]
}
proc getPresentConflictErrorMsg {curmodnamevr con_mod_list is_loading} {
if {[isModuleEvaluated any $curmodnamevr {} {*}$con_mod_list] || [getState\
force]} {
return [expr {$is_loading ? [getConLoadingMsg $con_mod_list] :\
[getConLoadedMsg $con_mod_list]}]
} else {
return [getErrConflictMsg $con_mod_list]
}
}
proc getForbiddenMsg {mod fpmod} {
set msg "Access to module [getModuleDesignation spec $mod 2] is denied"
set extramsg [getModuleTagProp $mod $fpmod forbidden message]
if {$extramsg ne {}} {
append msg \n$extramsg
}
return $msg
}
proc getNearlyForbiddenMsg {mod fpmod} {
set after [getModuleTagProp $mod $fpmod nearly-forbidden after]
set msg "Access to module will be denied starting '$after'"
set extramsg [getModuleTagProp $mod $fpmod nearly-forbidden message]
if {$extramsg ne {}} {
append msg \n$extramsg
}
return $msg
}
proc getWarningMsg {mod fpmod} {
return [getModuleTagProp $mod $fpmod warning message]
}
proc getStickyUnloadMsg {{tag sticky}} {
return "Unload of $tag module skipped"
}
proc getStickyForcedUnloadMsg {} {
return {Unload of sticky module forced}
}
proc getModWithAltVrIsLoadedMsg {mod is_loading} {
set vrdesiglist {}
foreach vr [getVariantList $mod 1] {
lappend vrdesiglist [sgr va $vr]
}
set state [expr {$is_loading ? {loading} : {loaded}}]
return "Variant [sgr se "\{"][join $vrdesiglist [sgr se :]][sgr se "\}"]\
is already $state"
}
proc getModFromDiffPathIsLoadedMsg {} {
return {Module already loaded from a different modulepath}
}
proc getEmptyNameMsg {type} {
return "Invalid empty $type name"
}
#
# Stack of message recording/eval unique identifiers
#
proc pushMsgRecordId {recid {setmsgid 1}} {
lappendState evalid $recid
if {$setmsgid} {
lappendState msgrecordid $recid
}
}
proc popMsgRecordId {{setmsgid 1}} {
lpopState evalid
if {$setmsgid} {
lpopState msgrecordid
}
}
proc clearAllMsgRecordId {} {
unsetState evalid
unsetState msgrecordid
}
#
# Format output text
#
# format an element with its syms for display in a list
proc formatListEltToDisplay {elt eltsgr eltsuffix sym_list symsgr show_syms\
sgrdef tag_list show_tags vr_list vrsgr show_vrs {himatchmap {}}\
{himatcharrvrmap {}} {himatcharrvrvalmap {}}} {
# fetch sgr codes from tags to apply directly on main element
if {$show_tags && [llength $tag_list]} {
# if more codes than character in elt, additional codes apply to the
# side tag list
lassign [getTagSgrForModname $tag_list [string length $elt]] tagsgrlist\
tag_list
} else {
set tagsgrlist {}
}
# display default sym graphically over element name
if {$show_syms} {
if {[set defidx [lsearch -exact $sym_list default]] != -1 && $sgrdef} {
set sym_list [lreplace $sym_list $defidx $defidx]
lappend eltsgrlist de
}
}
set displen 0
set disp $elt
lappend eltsgrlist $eltsgr
set dispsgr [sgr $eltsgrlist $elt $himatchmap $tagsgrlist]
# enclose name between quotes if a space is found
if {[string first { } $elt] != -1} {
incr displen 2
set dispsgr '$dispsgr'
}
# append suffix
append disp $eltsuffix
append dispsgr $eltsuffix
# format variant list if any
if {$show_vrs && [llength $vr_list]} {
array set himatchvrvalarr $himatcharrvrvalmap
array set himatchvrarr $himatcharrvrmap
set commasgr [sgr se ,]
set vrssgr "[sgr se \{]"
set vrs \{
foreach vrspec $vr_list {
lassign $vrspec vrname vrnameset vrvalues vrdflidx vrloadedidx\
loadedsgrkey
array unset vrvalsgridx
# apply sgr to default and loaded variant value
if {$vrdflidx != -1} {
lappend vrvalsgridx($vrdflidx) de
}
if {$vrloadedidx != -1} {
lappend vrvalsgridx($vrloadedidx) $loadedsgrkey
}
set vrsgrvalues $vrvalues
foreach vrvalidx [array names vrvalsgridx] {
lset vrsgrvalues $vrvalidx [sgr $vrvalsgridx($vrvalidx) [lindex\
$vrvalues $vrvalidx]]
}
if {[info exists notfirstvr]} {
set colonsgr [sgr se :]
append vrssgr $colonsgr
append vrs :
} else {
set notfirstvr 1
}
# highlight variant if corresponds to one set in query
if {[info exists himatchvrarr($vrname)]} {
set hivrmap $himatchvrarr($vrname)
set hivrvalmap $himatchvrvalarr($vrname)
} else {
set hivrmap {}
set hivrvalmap {}
}
if {[string length $vrnameset]} {
append vrssgr [sgr $vrsgr $vrnameset $hivrmap]
}
append vrssgr [sgr $vrsgr [lindex $vrsgrvalues 0] $hivrvalmap]
foreach vrvalue [lrange $vrsgrvalues 1 end] {
append vrssgr $commasgr[sgr $vrsgr $vrvalue $hivrvalmap]
}
append vrs $vrnameset[join $vrvalues :]
}
append vrssgr [sgr se \}]
append vrs \}
append dispsgr $vrssgr
append disp $vrs
}
# format remaining sym list
if {$show_syms && [llength $sym_list]} {
# track if a symbol has been reported excluding sym for alias '@'
if {![info exists ::g_used_sym_nocolor] && ([llength $sym_list] > 1 ||
[lindex $sym_list 0] ne {@})} {
set ::g_used_sym_nocolor 1
}
append disp "([join $sym_list :])"
set symssgr [sgr se (]
foreach sym $sym_list {
if {[info exists notfirstsym]} {
if {![info exists colonsgr]} {
set colonsgr [sgr se :]
}
append symssgr $colonsgr
} else {
set notfirstsym 1
}
append symssgr [sgr $symsgr $sym]
}
append symssgr [sgr se )]
append dispsgr $symssgr
}
# format tag list if any remaining
if {$show_tags && [llength $tag_list]} {
append disp " <[join $tag_list :]>"
set tagssgr " [sgr se <]"
foreach tag $tag_list {
# track tag name or abbreviation that have been used
if {![info exists ::g_used_tags($tag)]} {
set ::g_used_tags($tag) 1
}
if {[info exists notfirsttag]} {
if {![info exists colonsgr]} {
set colonsgr [sgr se :]
}
append tagssgr $colonsgr
} else {
set notfirsttag 1
}
# try to sgr in case a code apply to the tag
append tagssgr [sgr $tag $tag]
}
append tagssgr [sgr se >]
append dispsgr $tagssgr
}
# compute length
incr displen [string length $disp]
return [list $disp $dispsgr $displen]
}
# format an element with its syms for a long/detailed display in a list
proc formatListEltToLongDisplay {elt eltsgr eltsuffix sym_list symsgr mtime\
sgrdef {himatchmap {}}} {
# display default sym graphically over element name
if {[set defidx [lsearch -exact $sym_list default]] != -1 && $sgrdef} {
set sym_list [lreplace $sym_list $defidx $defidx]
lappend eltsgrlist de
}
lappend eltsgrlist $eltsgr
set displen 0
set disp $elt
set dispsgr [sgr $eltsgrlist $elt $himatchmap]
# enclose name between quotes if a space is found
if {[string first { } $elt] != -1} {
incr displen 2
set dispsgr '$dispsgr'
}
# append suffix
append disp $eltsuffix
append dispsgr $eltsuffix
# compute length
incr displen [string length $disp]
# format remaining sym list
if {[llength $sym_list]} {
set symslen [string length [join $sym_list :]]
foreach sym $sym_list {
if {![info exists colonsgr]} {
set colonsgr [sgr se :]
} else {
append symssgr $colonsgr
}
append symssgr [sgr $symsgr $sym]
}
} else {
set symssgr {}
set symslen 0
}
set nbws1 [expr {40 - $displen}]
set nbws2 [expr {$nbws1 < 0 ? 20 - $symslen + $nbws1 : 20 - $symslen}]
return [list $disp $dispsgr[string repeat { } $nbws1]$symssgr[string\
repeat { } $nbws2]$mtime $displen]
}
proc formatArrayValToJson {vallist} {
return [expr {[llength $vallist] ? "\[ \"[join $vallist {", "}]\" \]" :\
{[]}}]
}
proc formatObjectValToJson {objlist} {
foreach {key val isbool} $objlist {
if {[info exists disp]} {
append disp {, }
}
append disp "\"$key\": "
if {$isbool} {
append disp [expr {$val ? {true} : {false}}]
} else {
append disp "\"$val\""
}
}
##nagelfar ignore Bad expression
return [expr {[info exists disp] ? "{ $disp }" : "{}"}]
}
# format an element with its syms for a json display in a list
proc formatListEltToJsonDisplay {elt args} {
set disp "\"$elt\": \{ \"name\": \"$elt\""
foreach {key vtype val show} $args {
if {!$show} {
continue
}
append disp ", \"$key\": "
switch -- $vtype {
a {append disp [formatArrayValToJson $val]}
o {append disp [formatObjectValToJson $val]}
s {append disp "\"$val\""}
}
}
append disp "\}"
return $disp
}
# Prepare a map list to translate later on a substring in its highlighted
# counterpart. Translate substring into all module it specifies in case of an
# advanced version specification. Each string obtained is right trimmed from
# wildcard. No highlight is set for strings still containing wildcard chars
# after right trim operation. No highlist map is returned at all if highlight
# rendering is disabled.
proc prepareMapToHightlightSubstr {args} {
set maplist {}
if {[sgr hi {}] ne {}} {
foreach substr $args {
foreach m [getAllModulesFromVersSpec $substr] {
set m [string trimright $m {*?}]
if {$m ne {} && [string first * $m] == -1 && [string first ? $m]\
== -1} {
lappend maplist $m [sgr hi $m]
}
}
}
}
return $maplist
}
# Specific highlight translation map for variant name and value
proc prepareMapToHightlightVariant {args} {
if {[sgr hi {}] ne {}} {
foreach modspec $args {
foreach vrspec [getVariantListFromVersSpec $modspec] {
set vrvalues [lassign $vrspec vrname vrnot vrisbool]
if {![info exists vrname_map($vrname)]} {
set maplist [list $vrname [sgr hi $vrname]]
# also highlight shortcut if any
if {[info exists ::g_variantShortcut($vrname)]} {
lappend maplist $::g_variantShortcut($vrname) [sgr hi\
$::g_variantShortcut($vrname)]
}
set vrname_map($vrname) $maplist
}
# adapt variant value to highlight if boolean
set maplist {}
foreach vrvalue $vrvalues {
if {$vrisbool} {
set vrshort [expr {$vrvalue ? {+} : {-}}]$vrname
lappend maplist $vrshort [sgr hi $vrshort]
set vrvalue [expr {$vrvalue ? {on} : {off}}]
}
lappend maplist $vrvalue [sgr hi $vrvalue]
}
lappend vrval_map($vrname) {*}$maplist
}
}
}
return [list [array get vrname_map] [array get vrval_map]]
}
# Format list of modules obtained from a getModules call in upper context
proc reportModules {search_queries header hsgrkey hstyle show_mtime show_idx\
one_per_line theader_cols excluded_tag {mod_list_order {}}} {
# link to the result module list obtained in caller context
upvar mod_list mod_list
# output is JSON format
set json [isStateEqual report_format json]
# is some module variant specified in search query
set variant_spec_in_query 0
foreach modspec $search_queries {
if {[llength [getVariantListFromVersSpec $modspec]]} {
set variant_spec_in_query 1
break
}
}
# elements to include in output
if {[set report_indesym [isEltInReport indesym 0]]} {
set report_sym 0
} else {
set report_sym [isEltInReport sym]
}
set report_tag [isEltInReport tag]
set report_alias [expr {[isEltInReport alias] || [isEltInReport\
provided-alias]}]
# enable variant report if variantifspec configured and some variant is
# specified in query or variant configured for report or list sub-command
# json output
set report_variant [expr {($variant_spec_in_query && [isEltInReport\
variantifspec 0]) || [isEltInReport variant [expr {[currentState\
commandname] eq {list} && $json}]]}]
set collect_variant_from [expr {[currentState commandname] in {avail\
spider} ? {2} : {0}}]
# prepare list of tag abbreviations that can be substituted and list of
# tags whose name should be colored
getConf tag_abbrev
getConf tag_color_name
# prepare results for display
set alias_colored [isSgrkeyColored al]
set default_colored [isSgrkeyColored de]
set himatchmap [prepareMapToHightlightSubstr {*}$search_queries]
lassign [prepareMapToHightlightVariant {*}$search_queries]\
himatcharrvrmap himatcharrvrvalmap
set clean_list {}
set vr_list {}
set via [expr {[isEltInReport via] ? [getViaModuleForModulepath $header] :\
{}}]
# treat elements in specified order if any
##nagelfar ignore #2 Badly formed if statement
foreach elt [if {![llength $mod_list_order]} {array names mod_list}\
{set mod_list_order}] {
if {$report_variant} {
set vr_list [getVariantList $elt [expr {$json ? 4 : 7}] 0\
$collect_variant_from]
}
set sym_list [getVersAliasList $elt]
# fetch tags but clear excluded tag
set tag_list [replaceFromList [getTagList $elt [lindex $mod_list($elt)\
2]] $excluded_tag]
# abbreviate tags unless for json output
if {!$json} {
set tag_list [abbrevTagList $tag_list]
}
set dispsgr {}
# ignore "version" entries as symbolic version are treated
# along to their relative modulefile not independently
switch -- [lindex $mod_list($elt) 0] {
directory {
if {$json} {
##nagelfar ignore +2 Found constant
set dispsgr [formatListEltToJsonDisplay $elt type s directory\
1 symbols a $sym_list 1 via s $via 1]
} elseif {$show_mtime} {
# append / char after name to clearly indicate this is a dir
lassign [formatListEltToLongDisplay $elt di / $sym_list sy {}\
$default_colored $himatchmap] disp dispsgr displen
} else {
lassign [formatListEltToDisplay $elt di / $sym_list sy\
$report_sym $default_colored {} 0 {} {} 0 $himatchmap] disp\
dispsgr displen
}
}
modulefile - virtual {
if {$json} {
##nagelfar ignore +4 Found constant
set dispsgr [formatListEltToJsonDisplay $elt type s modulefile\
1 variants o $vr_list $report_variant symbols a $sym_list 1\
tags a $tag_list 1 pathname s [lindex $mod_list($elt) 2] 1\
via s $via 1]
} elseif {$show_mtime} {
set clock_mtime [expr {[lindex $mod_list($elt) 1] ne {} ?\
[clock format [lindex $mod_list($elt) 1] -format {%Y/%m/%d\
%H:%M:%S}] : {}}]
# add to display file modification time in addition
# to potential syms
lassign [formatListEltToLongDisplay $elt {} {} $sym_list sy\
$clock_mtime $default_colored $himatchmap] disp dispsgr\
displen
} else {
lassign [formatListEltToDisplay $elt {} {} $sym_list sy\
$report_sym $default_colored $tag_list $report_tag $vr_list\
va $report_variant $himatchmap $himatcharrvrmap\
$himatcharrvrvalmap] disp dispsgr displen
}
}
alias {
if {$json} {
##nagelfar ignore +3 Found constant
set dispsgr [formatListEltToJsonDisplay $elt type s alias 1\
symbols a $sym_list 1 tags a $tag_list 1 target s [lindex\
$mod_list($elt) 1] 1 via s $via 1]
} elseif {$show_mtime} {
lassign [formatListEltToLongDisplay $elt al " -> [lindex\
$mod_list($elt) 1]" $sym_list sy {} $default_colored\
$himatchmap] disp dispsgr displen
} elseif {$report_alias} {
# add a '@' sym to indicate elt is an alias if not colored
if {!$alias_colored} {
lappend sym_list @
# track use of '@' sym to add it to the output key
if {$report_sym && ![info exists ::g_used_alias_nocolor]} {
set ::g_used_alias_nocolor 1
}
}
lassign [formatListEltToDisplay $elt al {} $sym_list sy\
$report_sym $default_colored $tag_list $report_tag {} {} 0\
$himatchmap] disp dispsgr displen
}
}
version {
# report symbolic version independently from the module it is
# attached to. only done on regular or terse output when 'indesym'
# element is in relative output configuration option
if {$report_indesym} {
lassign [formatListEltToDisplay $elt sy {} {} {} 0 0 {} 0 {}\
{} 0 $himatchmap] disp dispsgr displen
}
}
}
if {$dispsgr ne {}} {
if {$json} {
lappend clean_list $dispsgr
} else {
lappend clean_list $disp
set sgrmap($disp) $dispsgr
set lenmap($disp) $displen
}
}
}
set len_list {}
set max_len 0
# dictionary-sort results unless if output order is specified
if {![llength $mod_list_order]} {
set clean_list [lsort -dictionary $clean_list]
}
if {$json} {
##nagelfar ignore Found constant
upvar 0 clean_list display_list
if {![info exists display_list]} {
set display_list {}
}
} else {
set display_list {}
foreach disp $clean_list {
# compute display element length list on sorted result
lappend display_list $sgrmap($disp)
lappend len_list $lenmap($disp)
if {$lenmap($disp) > $max_len} {
set max_len $lenmap($disp)
}
}
}
# output table header if needed and not yet done
if {[llength $display_list] && $show_mtime && ![isStateDefined\
theader_shown]} {
setState theader_shown 1
displayTableHeader {*}$theader_cols
}
# output formatted elements
displayElementList $header $hsgrkey $hstyle $one_per_line $show_idx 1\
$display_list $len_list $max_len $via
}
proc showModulePath {} {
set modpathlist [getModulePathList]
if {[llength $modpathlist]} {
report {Search path for module files (in search order):}
foreach path $modpathlist {
report " [sgr mp $path]"
}
} else {
reportWarning {No directories on module search path}
}
}
proc displayTableHeader {sgrkey args} {
foreach {title col_len} $args {
set col "- [sgr $sgrkey $title] "
append col [string repeat - [expr {$col_len - [string length $title] -\
3}]]
lappend col_list $col
}
report [join $col_list .]
}
proc displaySeparatorLine {{title {}} {sgrkey {}} {extra {}}} {
set tty_cols [getState term_columns]
if {$title eq {}} {
# adapt length if screen width is very small
set max_rep 67
set rep [expr {$tty_cols > $max_rep ? $max_rep : $tty_cols}]
report [string repeat - $rep]
} else {
set len [string length $title$extra]
set lrep [tcl::mathfunc::max [expr {($tty_cols - $len - 2)/2}] 1]
set rrep [tcl::mathfunc::max [expr {$tty_cols - $len - 2 - $lrep}] 1]
report "[string repeat - $lrep] [sgr $sgrkey $title]$extra [string\
repeat - $rrep]"
}
}
# get a list of elements and print them in a column or in a
# one-per-line fashion
proc displayElementList {header sgrkey hstyle one_per_line display_idx\
start_idx display_list {len_list {}} {max_len 0} {via {}}} {
set elt_cnt [llength $display_list]
reportDebug "header=$header, sgrkey=$sgrkey, hstyle=$hstyle,\
elt_cnt=$elt_cnt, max_len=$max_len, one_per_line=$one_per_line,\
display_idx=$display_idx, start_idx=$start_idx, via=$via"
# end proc if no element are to print
if {$elt_cnt == 0} {
return
}
# output is JSON format
set json [isStateEqual report_format json]
# display header if any provided
if {$header ne {noheader}} {
set header [getModulepathLabel $header]
if {$json} {
report "\"$header\": \{"
} elseif {$hstyle eq {sepline}} {
set extra [expr {[string length $via] ? " (via $via)" : {}}]
displaySeparatorLine $header $sgrkey $extra
} else {
report [sgr $sgrkey $header]:
}
}
# increase index length when 100+ modules to report
if {$display_idx} {
set idx_len [expr {$elt_cnt > 99 ? {3} : {2}}]
}
if {$json} {
set displist [join $display_list ,\n]
# display one element per line
} elseif {$one_per_line} {
if {$display_idx} {
set idx $start_idx
foreach elt $display_list {
append displist [format "%${idx_len}d) %s " $idx $elt] \n
incr idx
}
} else {
append displist [join $display_list \n] \n
}
# elsewhere display elements in columns
} else {
# save room for numbers and spacing: 2 or 3 digits + ) + space
set elt_prefix_len [expr {$display_idx ? $idx_len + 2 : {0}}]
# save room for two spaces after element
set elt_suffix_len 2
# compute rows*cols grid size with optimized column number
# the size of each column is computed to display as much column
# as possible on each line
incr max_len $elt_suffix_len
foreach len $len_list {
lappend elt_len [incr len $elt_suffix_len]
}
set tty_cols [getState term_columns]
# find valid grid by starting with non-optimized solution where each
# column length is equal to the length of the biggest element to display
set cur_cols [tcl::mathfunc::max [expr {int(($tty_cols - \
$elt_prefix_len) / $max_len)}] 0]
# when display is found too short to display even one column
if {$cur_cols == 0} {
set cols 1
set rows $elt_cnt
array set col_width [list 0 $max_len]
} else {
set cols 0
set rows 0
}
set last_round 0
set restart_loop 0
while {$cur_cols > $cols} {
if {!$restart_loop} {
if {$last_round} {
incr cur_rows
} else {
set cur_rows [expr {int(ceil(double($elt_cnt) / $cur_cols))}]
}
for {set i 0} {$i < $cur_cols} {incr i} {
set cur_col_width($i) 0
}
for {set i 0} {$i < $cur_rows} {incr i} {
set row_width($i) 0
}
set istart 0
} else {
##nagelfar ignore Unknown variable
set istart [expr {$col * $cur_rows}]
# only remove width of elements from current col
for {set row 0} {$row < ($i % $cur_rows)} {incr row} {
##nagelfar ignore Unknown variable
incr row_width($row) -[expr {$pre_col_width + $elt_prefix_len}]
}
}
set restart_loop 0
for {set i $istart} {$i < $elt_cnt} {incr i} {
set col [expr {int($i / $cur_rows)}]
set row [expr {$i % $cur_rows}]
# restart loop if a column width change
if {[lindex $elt_len $i] > $cur_col_width($col)} {
set pre_col_width $cur_col_width($col)
set cur_col_width($col) [lindex $elt_len $i]
set restart_loop 1
break
}
# end search of maximum number of columns if computed row width
# is larger than terminal width
if {[incr row_width($row) +[expr {$cur_col_width($col) \
+ $elt_prefix_len}]] > $tty_cols} {
# start last optimization pass by increasing row number until
# reaching number used for previous column number, by doing so
# this number of column may pass in terminal width, if not
# fallback to previous number of column
if {$last_round && $cur_rows == $rows} {
incr cur_cols -1
} else {
set last_round 1
}
break
}
}
# went through all elements without reaching terminal width limit so
# this number of column solution is valid, try next with a greater
# column number
if {$i == $elt_cnt} {
set cols $cur_cols
set rows $cur_rows
array set col_width [array get cur_col_width]
# number of column is fixed if last optimization round has started
# reach end also if there is only one row of results
if {!$last_round && $rows > 1} {
incr cur_cols
}
}
}
reportDebug list=$display_list
reportDebug "rows/cols=$rows/$cols,\
lastcol_item_cnt=[expr {int($elt_cnt % $rows)}]"
for {set row 0} {$row < $rows} {incr row} {
for {set col 0} {$col < $cols} {incr col} {
set index [expr {$col * $rows + $row}]
if {$index < $elt_cnt} {
if {$display_idx} {
append displist [format "%${idx_len}d) " [expr {$index +\
$start_idx}]]
}
# cannot use 'format' as strings may contain SGR codes
append displist [lindex $display_list $index][string repeat\
{ } [expr {$col_width($col) - [lindex $len_list $index]}]]
}
}
append displist \n
}
}
if {$json && $header ne {noheader}} {
append displist "\n\}"
}
report $displist 1
reportSeparateNextContent
}
# Report an output key to help understand what the SGR used on this output
# correspond to
proc displayKey {} {
# specific key entry for symbolic version if reported independently
set typesym [list {symbolic-version}]
if {![isEltInReport indesym 0]} {
lappend typesym [sgr se (]<SGR>[sgr se )] 18
}
array set skipsgr [list hi 1 db 1 tr 1 se 1 er 1 wa 1 me 1 in 1 cm 1 va 1]
array set typesgr [list mp modulepath di [list directory <SGR>/ 10] al\
module-alias sy $typesym de [list {default-version}]]
set display_list {}
set len_list {}
foreach key [array names ::g_used_colors] {
# sgr key matches a basic modulefile type
if {[info exists typesgr($key)]} {
# the way to describe key is already defined
if {[llength $typesgr($key)] > 1} {
lassign $typesgr($key) desc desctmp len
set desc [string map [list <SGR> [sgr $key $desc]] $desctmp]
} else {
set desc [lindex $typesgr($key) 0]
}
if {$key eq {sy} && [info exists ::g_used_sym_nocolor]} {
unset ::g_used_sym_nocolor
}
# key is a tag abbreviation
} elseif {[info exists ::g_abbrevTag($key)]} {
set desc $::g_abbrevTag($key)
# if not part of the ignored list, this key corresponds to a tag name
} elseif {![info exists skipsgr($key)]} {
set desc $key
}
if {[info exists desc]} {
# define key description
if {![info exists len]} {
set len [string length $desc]
set desc [sgr $key $desc]
}
lappend display_list $desc
lappend len_list $len
unset desc
unset len
}
}
# include var=val key if any other variant form is present in report
if {![info exists ::g_used_va(val)] && [array exists ::g_used_va]} {
set ::g_used_va(val) 1
}
# add key for variant reports
if {[info exists ::g_used_va(on)]} {
lappend display_list "[sgr se \{][sgr va +variant][sgr se\
\}]=[sgr se \{][sgr va variant=on][sgr se \}]"
lappend len_list 23
}
if {[info exists ::g_used_va(off)]} {
lappend display_list "[sgr se \{][sgr va -variant][sgr se\
\}]=[sgr se \{][sgr va variant=off][sgr se \}]"
lappend len_list 24
}
foreach sc [array names ::g_used_va] {
if {$sc ni {on off val}} {
lappend display_list "[sgr se \{][sgr va ${sc}value][sgr se\
\}]=[sgr se \{][sgr va $::g_used_va($sc)=value][sgr se \}]"
lappend len_list [expr {17 + [string length $::g_used_va($sc)]}]
}
}
# finish with variant=value entry as it is referred by other variant keys
if {[info exists ::g_used_va(val)]} {
lappend display_list "[sgr se \{][sgr va variant=value][sgr se \}]"
lappend len_list 15
}
# add key for alias if '@' put in parentheses
if {[info exists ::g_used_alias_nocolor]} {
lappend display_list "[sgr se (]@[sgr se )]=module-alias"
lappend len_list 9
}
# add key for symbolic version if any put in parentheses but no color
if {[info exists ::g_used_sym_nocolor]} {
lappend display_list "[sgr se (]symbolic-version[sgr se )]"
lappend len_list 18
}
# add key for module tag if any put in angle brackets
if {[array exists ::g_used_tags]} {
lappend display_list "[sgr se <]module-tag[sgr se >]"
lappend len_list 12
}
# report translation of each uncolored tag abbreviation that have been used
foreach tag [array names ::g_used_tags] {
if {![info exists ::g_used_colors($tag)] && [info exists\
::g_abbrevTag($tag)]} {
lappend display_list [sgr se <]$tag[sgr se >]=$::g_abbrevTag($tag)
lappend len_list [expr {[string length $tag] + [string length\
$::g_abbrevTag($tag)] + 3}]
}
}
# find largest element
set max_len 0
foreach len $len_list {
if {$len > $max_len} {
set max_len $len
}
}
if {[llength $display_list]} {
# display header
report Key:
# display key content
displayElementList noheader {} {} 0 0 0 $display_list $len_list $max_len
}
}
# Return conf value and from where an eventual def value has been overridden
proc displayConfig {val env_var {asked 0} {trans {}} {locked 0}} {
array set transarr $trans
# get overridden value and know what has overridden it
if {$asked} {
set defby " (cmd-line)"
} elseif {$env_var ne {} && !$locked && [isEnvVarDefined $env_var]} {
set defby " (env-var)"
} elseif {$locked} {
set defby " (locked)"
} else {
set defby {}
}
# translate fetched value if translation table exists
if {[info exists transarr($val)]} {
set val $transarr($val)
}
return $val$defby
}
# report linter output as error/warning messages
proc displayLinterOutput {linter output} {
switch -- $linter {
nagelfar {
# parsing linter output
set report_list {}
foreach line [split $output \n] {
set firstword [string range $line 0 [string first { } $line]-1]
switch -- $firstword {
Checking - Parsing {}
Line {
# add message of previous line if any
if {[info exists msg]} {
lappend report_list $msg
}
# extract information from message line
set colidx [string first : $line]
set linenum [string trimleft [string range $line 5\
$colidx-1]]
set severity [string index $line $colidx+2]
switch -- $severity {
W {
set severity WARNING
set sgrkey wa
set raisecnt 0
}
E {
set severity ERROR
set sgrkey er
set raisecnt 1
}
default {
set severity NOTICE
set sgrkey in
set raisecnt 0
}
}
set msg [string range $line $colidx+4 end]
# start recorded message properties
lappend report_list $linenum $severity $sgrkey $raisecnt
}
default {
# this line is continuing message started previously
append msg \n[string trimleft $line]
}
}
}
# add message of last line if any
if {[info exists msg]} {
lappend report_list $msg
unset msg
}
# report messages
foreach {linenum severity sgrkey raisecnt mesg} $report_list {
reportError $mesg "[format %-7s $severity] line $linenum"\
$sgrkey $raisecnt
}
}
default {
reportError $output
}
}
}
proc reportMlUsage {} {
reportVersion
report {Usage: ml [options] [command] [args ...]
ml [options] [[-]modulefile ...]
Examples:
ml equivalent to: module list
ml foo bar equivalent to: module load foo bar
ml -foo -bar baz equivalent to: module unload foo bar; module load baz
ml avail -t equivalent to: module avail -t
See 'module --help' to get available commands and options.}
}
proc reportUsage {} {
reportVersion
##nagelfar ignore #111 Too long line
report {Usage: module [options] [command] [args ...]
Loading / Unloading commands:
add | load modulefile [...] Load modulefile(s)
try-add | try-load modfile [...] Load modfile(s), no complain if not found
add-any | load-any modfile [...] Load first available modulefile in list
rm | unload modulefile [...] Remove modulefile(s)
purge Unload all loaded modulefiles
reload | update Unload then load all loaded modulefiles
switch | swap [mod1] mod2 Unload mod1 and load mod2
refresh Refresh loaded module volatile components
reset Restore initial environment
Listing / Searching commands:
list [-a] [-t|-l|-j] [-S|-C] [mod ...]
List all or matching loaded modules
avail [-a] [-t|-l|-j] [-S|-C] [-d|-L] [--indepth|--no-indepth] [mod ...]
List all or matching available modules
aliases [-a] List all module aliases
whatis [-a] [-j] [modulefile ...] Print whatis information of modulefile(s)
apropos | keyword | search [-a] [-j] str
Search all name and whatis containing str
spider [-a] [-t|-l|-j] [-S|-C] [-d|-L] [--indepth|--no-indepth] [mod ...]
Scan all modulepaths and list all or
matching available modules
is-loaded [modulefile ...] Test if any of the modulefile(s) are loaded
is-avail modulefile [...] Is any of the modulefile(s) available
info-loaded modulefile Get full name of matching loaded module(s)
Collection of modules handling commands:
save [collection|file] Save current module list to collection
restore [collection|file] Restore module list from collection or file
saverm | disable [collection] Remove saved collection
saveshow | describe [coll|file] Display information about collection
savelist [-a] [-t|-l|-j] [-S|-C] [collection ...]
List all or matching saved collections
is-saved [collection ...] Test if any of the collection(s) exists
stash Save current environment and reset
stashpop [stash] Restore then remove stash collection
stashrm [stash] Remove stash collection
stashshow [stash] Display information about stash collection
stashclear Remove all stash collections
stashlist List all stash collections
Environment direct handling commands:
prepend-path [-d c] var val [...] Prepend value to environment variable
append-path [-d c] var val [...] Append value to environment variable
remove-path [-d c] var val [...] Remove value from environment variable
Module cache handling commands:
cachebuild [modulepath ...] Create cache file for modulepath(s)
cacheclear Delete cache file in enabled modulepath(s)
Other commands:
help [modulefile ...] Print this or modulefile(s) help info
display | show modulefile [...] Display information about modulefile(s)
test [modulefile ...] Test modulefile(s)
use [-a|-p] dir [...] Add dir(s) to MODULEPATH variable
unuse dir [...] Remove dir(s) from MODULEPATH variable
is-used [dir ...] Is any of the dir(s) enabled in MODULEPATH
path modulefile Print modulefile path
paths modulefile Print path of matching available modules
clear [-f] Reset Modules-specific runtime information
source scriptfile [...] Execute scriptfile(s)
config [--dump-state|name [val]] Display or set Modules configuration
state [name] Display Modules state
sh-to-mod shell shellscript [arg ...]
Make modulefile from script env changes
mod-to-sh shell modulefile [...]
Make shell code from modulefile env changes
edit modulefile Open modulefile in editor
lint [-a] [modulefile ...] Check syntax of modulefile
Switches:
-t | --terse Display output in terse format
-l | --long Display output in long format
-j | --json Display output in JSON format
-o LIST | --output=LIST
Define elements to output on 'avail', 'spider' or 'list'
sub-cmds in addition to module names (LIST is made of items
like 'sym', 'tag', 'variant' or 'key' separated by ':')
-a | --all Include hidden modules in search
-d | --default Only show default versions available
-L | --latest Only show latest versions available
-S | --starts-with
Search modules whose name begins with query string
-C | --contains Search modules whose name contains query string
-i | --icase Case insensitive match
-a | --append Append directory to MODULEPATH (on 'use' sub-command)
-p | --prepend Prepend directory to MODULEPATH
--auto Enable automated module handling mode
--no-auto Disable automated module handling mode
-f | --force By-pass dependency consistency, abort on error or
confirmation dialog
--tag=LIST Apply tag to loading module on 'load', 'try-load', 'load-any'
or 'switch' sub-commands (LIST is made of tag names
separated by ':')
--ignore-cache Ignore module cache
--ignore-user-rc
Skip evaluation of user-specific module rc file
Options:
-h | --help This usage info
-V | --version Module version
--dumpname Module implementation name
-D | --debug Enable debug messages
-T | --trace Enable trace messages
-v | --verbose Enable verbose messages
-s | --silent Turn off error, warning and informational messages
--timer Report execution times
--paginate Pipe mesg output into a pager if stream attached to terminal
--no-pager Do not pipe message output into a pager
--redirect Send output to stdout (only for sh, bash, ksh, zsh and fish)
--no-redirect Send output to stderr
--color[=WHEN] Colorize the output; WHEN can be 'always' (default if
omitted), 'auto' or 'never'
-w COLS | --width=COLS
Set output width to COLS columns.}
}
# create appropriate message and kind of report when a requirement is not
# satisfied
proc reportMissingPrereqError {curmodnamevr modulepath_list args} {
set is_path_specific [llength $modulepath_list]
if {[isModuleEvaluated reqlo $curmodnamevr $modulepath_list {*}$args]} {
set msg [getErrReqLoMsg $args $is_path_specific]
} else {
set retiseval [isModuleEvaluated any $curmodnamevr $modulepath_list\
{*}$args]
# more appropriate msg if an evaluation was attempted or is by-passed
set msg [expr {$retiseval || [getState force] ? [getReqNotLoadedMsg\
$args $is_path_specific] : [getErrPrereqMsg $args 1\
$is_path_specific]}]
}
knerrorOrWarningIfForced $msg MODULES_ERR_GLOBAL
}
proc setConflictErrorAsReported {args} {
appendNoDupToList ::report_conflict([currentState evalid]) {*}$args
# save content added to remove it later if evaluation is withdrawn
if {[depthState reportholdid]} {
lappend ::g_holdReportConflict([currentState reportholdid]) \
[currentState evalid] $args
}
}
proc isConflictErrorAlreadyReported {msgrecid mod_con_list} {
if {[info exists ::report_conflict($msgrecid)]} {
return [isIntBetweenList $mod_con_list $::report_conflict($msgrecid)]
} else {
return 0
}
}
# Report final error caught on main catch block
proc reportFinalError {error_msg} {
# render error if not done yet
if {$::errorCode ne {MODULES_ERR_RENDERED}} {
incrErrorCount
renderFalse
}
if {$::errorCode ni [list MODULES_ERR_RENDERED MODULES_ERR_KNOWN]} {
# add web link to report issue unless if an external error is detected
set external_error_list [list\
{Can't find a usable init.tcl in the following directories}\
{interpreter uses an incompatible stubs mechanism}\
{dlopen(}\
{couldn't fork child process: resource temporarily unavailable}\
{invalid command name "tcl::mathfunc::max"}]
set add_report_link 1
foreach external_error $external_error_list {
if {[string equal -length [string length $external_error]\
$external_error $error_msg]} {
set add_report_link 0
break
}
}
# report stack trace in addition to the error msg if error is unknown
set error_msg $::errorInfo
if {$add_report_link} {
append error_msg \n[sgr hi {Please report this issue at\
https://github.com/envmodules/modules/issues}]
}
}
reportError $error_msg
}
# ;;; Local Variables: ***
# ;;; mode:tcl ***
# ;;; End: ***
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent:
|