| 1 |
########################################################################## |
| 2 |
|
| 3 |
# REPORT.TCL, output handling procedures |
| 4 |
# Copyright (C) 2002-2004 Mark Lakata |
| 5 |
# Copyright (C) 2004-2017 Kent Mein |
| 6 |
# Copyright (C) 2016-2025 Xavier Delaruelle |
| 7 |
# |
| 8 |
# This program is free software: you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation, either version 2 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
########################################################################## |
| 22 |
|
| 23 |
# |
| 24 |
# Debug, Info, Warnings and Error message handling. |
| 25 |
# |
| 26 |
|
| 27 |
# save message when report is not currently initialized as we do not |
| 28 |
# know yet if debug mode is enabled or not |
| 29 |
proc reportDebug {message {caller _undef_}} { |
| 30 |
set caller [getCallingProcName] |
| 31 |
lappend ::errreport_buffer [list reportDebug $message $caller] |
| 32 |
} |
| 33 |
|
| 34 |
# regular procedure to use once error report is initialized |
| 35 |
proc __reportDebug {message {caller _undef_}} { |
| 36 |
# display active interp details if not the main one |
| 37 |
set prefix [currentState debug_msg_prefix] |
| 38 |
if {$caller eq {_undef_}} { |
| 39 |
set caller [getCallingProcName] |
| 40 |
} |
| 41 |
# display caller name as prefix |
| 42 |
if {$caller ne {}} { |
| 43 |
append prefix "$caller: " |
| 44 |
} |
| 45 |
report [sgr db "DEBUG $prefix$message"] 0 1 |
| 46 |
} |
| 47 |
|
| 48 |
# alternative procedure used when debug is disabled |
| 49 |
proc __reportDebugNop {message {caller _undef_}} {} |
| 50 |
|
| 51 |
proc reportWarning {message} { |
| 52 |
reportError $message WARNING wa 0 |
| 53 |
} |
| 54 |
|
| 55 |
proc reportError {message {severity ERROR} {sgrkey er} {incr_count 1}} { |
| 56 |
lappend ::errreport_buffer [list reportError $message $severity $sgrkey\ |
| 57 |
$incr_count] |
| 58 |
} |
| 59 |
|
| 60 |
proc __reportError {message {severity ERROR} {sgrkey er} {incr_count 1}} { |
| 61 |
# if report disabled, also disable error raise to get a coherent behavior |
| 62 |
# (if no message printed, no error code change). also no report if no msg |
| 63 |
if {![getState inhibit_errreport] && [string length $message]} { |
| 64 |
if {$incr_count} { |
| 65 |
incrErrorCount |
| 66 |
} |
| 67 |
set msgsgr "[sgr $sgrkey $severity]: $message" |
| 68 |
# record message to report it later on if a record id is found |
| 69 |
if {[currentState msgrecordid] ne {}} { |
| 70 |
recordMessage $msgsgr |
| 71 |
# skip message report if silent |
| 72 |
} elseif {[isVerbosityLevel concise]} { |
| 73 |
# save error messages to render them all together in JSON format |
| 74 |
if {[isStateEqual report_format json]} { |
| 75 |
lappend ::g_report_erralist $severity $message |
| 76 |
} else { |
| 77 |
report $msgsgr 0 0 1 |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
# throw known error (call error with 'known error' code) |
| 84 |
proc knerror {message {code MODULES_ERR_KNOWN}} { |
| 85 |
error $message {} $code |
| 86 |
} |
| 87 |
|
| 88 |
proc knerrorOrWarningIfForced {message {code MODULES_ERR_KNOWN}} { |
| 89 |
if {[getState force]} { |
| 90 |
reportWarning $message |
| 91 |
} else { |
| 92 |
knerror $message $code |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
# save message if report is not yet initialized |
| 97 |
proc reportErrorAndExit {message} { |
| 98 |
lappend ::errreport_buffer [list reportErrorAndExit $message] |
| 99 |
} |
| 100 |
|
| 101 |
# regular procedure to use once error report is initialized |
| 102 |
proc __reportErrorAndExit {message} { |
| 103 |
incrErrorCount |
| 104 |
renderFalse |
| 105 |
error $message {} MODULES_ERR_RENDERED |
| 106 |
} |
| 107 |
|
| 108 |
proc reportErrorOrWarningIfForced {message} { |
| 109 |
if {[getState force]} { |
| 110 |
reportWarning $message |
| 111 |
} else { |
| 112 |
reportError $message |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
proc reportInternalBug {message {modfile {}} {title {Module ERROR}}} { |
| 117 |
reportError [formatInternalBugMsg $message $modfile] $title me |
| 118 |
} |
| 119 |
|
| 120 |
proc reportInternalBugWarning {message {modfile {}} {title {Module\ |
| 121 |
WARNING}}} { |
| 122 |
reportError [formatInternalBugMsg $message $modfile] $title wa 0 |
| 123 |
} |
| 124 |
|
| 125 |
proc reportInternalBugOrWarningIfForced {message {modfile {}}} { |
| 126 |
if {[getState force]} { |
| 127 |
reportInternalBugWarning $message $modfile |
| 128 |
} else { |
| 129 |
reportInternalBug $message $modfile |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
proc formatInternalBugMsg {message modfile} { |
| 134 |
if {$modfile ne {}} { |
| 135 |
set message [formatMessageInModule $message $modfile] |
| 136 |
} |
| 137 |
return "$message\nPlease contact <[getConf contact]>" |
| 138 |
} |
| 139 |
|
| 140 |
proc formatMessageInModule {message modfile} { |
| 141 |
return "$message\nIn '$modfile'" |
| 142 |
} |
| 143 |
|
| 144 |
proc reportInfo {message {title INFO}} { |
| 145 |
if {[isVerbosityLevel normal]} { |
| 146 |
# use reportError for convenience but there is no error here |
| 147 |
reportError $message $title in 0 |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
proc reportTrace {message {title TRACE}} { |
| 152 |
if {[isVerbosityLevel trace]} { |
| 153 |
# use reportError for convenience but there is no error here |
| 154 |
reportError [sgr tr $message] $title tr 0 |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
proc reportTimer {message timestr start_us stop_us} { |
| 159 |
set elapsed_ms [expr {($stop_us - $start_us) / 1000.0}] |
| 160 |
report [sgr db "TIMER $message [format $timestr $elapsed_ms]"] 0 1 |
| 161 |
} |
| 162 |
|
| 163 |
# trace procedure execution start |
| 164 |
proc reportTraceExecEnter {cmdstring op} { |
| 165 |
reportDebug $cmdstring [getCallingProcName] |
| 166 |
} |
| 167 |
|
| 168 |
# time procedure execution duration |
| 169 |
proc reportTimerExecEnter {cmdstring op} { |
| 170 |
uplevel 1 set proc_timer_start [clock microseconds] |
| 171 |
} |
| 172 |
|
| 173 |
proc reportTimerExecLeave {cmdstring code result op} { |
| 174 |
reportTimer $cmdstring {(%.3f ms)} [uplevel 1 set proc_timer_start]\ |
| 175 |
[clock microseconds] |
| 176 |
} |
| 177 |
|
| 178 |
# record messages on the eventual additional module evaluations that have |
| 179 |
# occurred during the current evaluation |
| 180 |
proc reportModuleEval {} { |
| 181 |
set evalid [currentState evalid] |
| 182 |
array set contexttitle {conun {Unloading conflict} reqlo {Loading\ |
| 183 |
requirement} depre {Reloading dependent} depun {Unloading dependent}\ |
| 184 |
urequn {Unloading useless requirement}} |
| 185 |
|
| 186 |
if {[info exists ::g_moduleEval($evalid)]} { |
| 187 |
foreach contextevallist $::g_moduleEval($evalid) { |
| 188 |
set msgrecidlist [lassign $contextevallist context] |
| 189 |
# skip context with no description title |
| 190 |
if {[info exists contexttitle($context)]} { |
| 191 |
# exclude hidden modules from report unless an high level of |
| 192 |
# verbosity is set |
| 193 |
if {[info exists ::g_moduleHiddenEval($evalid:$context)] &&\ |
| 194 |
![isVerbosityLevel verbose2]} { |
| 195 |
lassign [getDiffBetweenList $msgrecidlist\ |
| 196 |
$::g_moduleHiddenEval($evalid:$context)] msgrecidlist |
| 197 |
} |
| 198 |
|
| 199 |
if {[llength $msgrecidlist]} { |
| 200 |
set moddesiglist {} |
| 201 |
foreach msgrecid $msgrecidlist { |
| 202 |
lappend moddesiglist [getModuleDesignation $msgrecid] |
| 203 |
} |
| 204 |
reportInfo [join $moddesiglist] $contexttitle($context) |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
# purge list in case same evaluation is re-done afterward |
| 209 |
unset ::g_moduleEval($evalid) |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
# render messages related to current record id under an header block |
| 214 |
proc reportMsgRecord {header {hidden 0}} { |
| 215 |
set recid [currentState msgrecordid] |
| 216 |
if {[info exists ::g_msgRecord($recid)]} { |
| 217 |
# skip message report if silent (report even if hidden as soon as msgs |
| 218 |
# are associated to hidden module evaluation) |
| 219 |
if {[isVerbosityLevel concise]} { |
| 220 |
set tty_cols [getState term_columns] |
| 221 |
set padding { } |
| 222 |
|
| 223 |
set dispmsg $header |
| 224 |
foreach msg $::g_msgRecord($recid) { |
| 225 |
# split lines if too large for terminal |
| 226 |
set first 1 |
| 227 |
set max_idx [tcl::mathfunc::max [expr {$tty_cols - [string length\ |
| 228 |
$padding]}] 1] |
| 229 |
set linelist [list] |
| 230 |
foreach line [split $msg \n] { |
| 231 |
set lineadd {} |
| 232 |
while {$lineadd ne $line} { |
| 233 |
set line_max_idx $max_idx |
| 234 |
# sgr tags consume no length |
| 235 |
set eidx 0 |
| 236 |
while {[set sidx [string first "\033\[" $line $eidx]] !=\ |
| 237 |
-1} { |
| 238 |
set eidx [string first m $line $sidx] |
| 239 |
incr line_max_idx [expr {1 + $eidx - $sidx}] |
| 240 |
} |
| 241 |
|
| 242 |
# no split if no whitespace found to slice |
| 243 |
if {[string length $line] > $line_max_idx && [set cut_idx\ |
| 244 |
[string last { } $line $line_max_idx]] != -1} { |
| 245 |
set lineadd [string range $line 0 $cut_idx-1] |
| 246 |
set line [string range $line $cut_idx+1 end] |
| 247 |
} else { |
| 248 |
set lineadd $line |
| 249 |
} |
| 250 |
# skip empty line |
| 251 |
if {[string trim $lineadd] ne {}} { |
| 252 |
lappend linelist $lineadd |
| 253 |
} |
| 254 |
if {$first} { |
| 255 |
set first 0 |
| 256 |
incr max_idx -[string length $padding] |
| 257 |
if {$max_idx < 1} {set max_idx 1} |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
# display each line |
| 263 |
set first 1 |
| 264 |
foreach line $linelist { |
| 265 |
append dispmsg \n |
| 266 |
if {$first} { |
| 267 |
set first 0 |
| 268 |
} else { |
| 269 |
append dispmsg $padding |
| 270 |
} |
| 271 |
append dispmsg $padding$line |
| 272 |
} |
| 273 |
} |
| 274 |
reportSeparateNextContent |
| 275 |
report $dispmsg |
| 276 |
reportSeparateNextContent |
| 277 |
} |
| 278 |
|
| 279 |
# purge message list in case same evaluation is re-done afterward |
| 280 |
unset ::g_msgRecord($recid) |
| 281 |
# report header if no other specific msg to output in verbose mode or in |
| 282 |
# normal verbosity mode if currently processing a cmd which triggers |
| 283 |
# multiple module evaluations that cannot be guessed by the user (excluding |
| 284 |
# dependency evaluations which are reported by triggering top evaluation) |
| 285 |
# if hidden flag is enabled report only if verbosity >= verbose2 |
| 286 |
} elseif {(!$hidden && ([isVerbosityLevel verbose] || ([isVerbosityLevel\ |
| 287 |
normal] && ([ongoingCommandName restore] || [ongoingCommandName source]\ |
| 288 |
|| [ongoingCommandName reset] || [ongoingCommandName stash] ||\ |
| 289 |
[ongoingCommandName stashpop] || [ongoingCommandName cacheclear] ||\ |
| 290 |
[ongoingCommandName cachebuild]) && $recid eq [topState msgrecordid])))\ |
| 291 |
|| ($hidden && [isVerbosityLevel verbose2])} { |
| 292 |
report $header |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
# separate next content produced if any |
| 297 |
proc reportSeparateNextContent {} { |
| 298 |
lappend ::errreport_buffer [list reportSeparateNextContent] |
| 299 |
} |
| 300 |
|
| 301 |
# regular procedure to use once error report is initialized |
| 302 |
proc __reportSeparateNextContent {} { |
| 303 |
# hold or apply |
| 304 |
if {[depthState reportholdid] > 0} { |
| 305 |
lappend ::g_holdReport([currentState reportholdid]) [list\ |
| 306 |
reportSeparateNextContent] |
| 307 |
} else { |
| 308 |
setState report_sep_next 1 |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
# save message for block rendering |
| 313 |
proc recordMessage {message} { |
| 314 |
set recid [currentState msgrecordid] |
| 315 |
|
| 316 |
if {$recid eq [currentState reportholdrecid]} { |
| 317 |
lappend ::g_holdReport([currentState reportholdid]) [list\ |
| 318 |
recordMessage $message] |
| 319 |
} else { |
| 320 |
lappend ::g_msgRecord($recid) $message |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
# check if some msg have been recorded for current evaluation |
| 325 |
proc isMsgRecorded {} { |
| 326 |
return [info exists ::g_msgRecord([currentState msgrecordid])] |
| 327 |
} |
| 328 |
|
| 329 |
# filter and format error stack trace to only report useful content |
| 330 |
proc formatErrStackTrace {errmsg loc {cmdlist {}}} { |
| 331 |
set headstr "\n while executing\n" |
| 332 |
set splitstr "\n invoked from within\n" |
| 333 |
set splitstrlen [string length $splitstr] |
| 334 |
set aftheadidx [string first $headstr $errmsg] |
| 335 |
if {$aftheadidx != -1} { |
| 336 |
incr aftheadidx [string length $headstr] |
| 337 |
} |
| 338 |
|
| 339 |
# get name of invalid command name to maintain it in error stack trace |
| 340 |
if {[string equal -length 22 {invalid command name "} $errmsg]} { |
| 341 |
set unkcmd [lindex [split [string range $errmsg 0 $aftheadidx] {"}] 1] |
| 342 |
} else { |
| 343 |
set unkcmd {} |
| 344 |
} |
| 345 |
|
| 346 |
# get list of modulecmd.tcl internal procedure to filter out from stack |
| 347 |
# also add the way subcmds are launched through module proc ($cmdprocname) |
| 348 |
# skip this when no interp command list is provided |
| 349 |
if {[llength $cmdlist]} { |
| 350 |
lassign [getDiffBetweenList [list {*}[info commands] {*}[info procs]\ |
| 351 |
{$cmdprocname}] $cmdlist] filtercmdlist keepcmdlist |
| 352 |
} else { |
| 353 |
set filtercmdlist {} |
| 354 |
} |
| 355 |
|
| 356 |
# define commands to filter out from bottom of stack |
| 357 |
set filtercmdendlist [list {eval [getModuleContent\ |
| 358 |
$::ModulesCurrentModulefile]} "source $loc" {uplevel 1 source\ |
| 359 |
$siteconfig} {eval $cachecontent}] |
| 360 |
# define commands to filter out from middle of stack |
| 361 |
set filtercmdmidlist [list {interp eval $itrp $::source_cache($filename)}] |
| 362 |
|
| 363 |
# filter out modulecmd internal references at beginning of stack |
| 364 |
set internals 1 |
| 365 |
while {$internals && $aftheadidx != -1} { |
| 366 |
# fetch erroneous command and its caller |
| 367 |
set stackelt [string range $errmsg $aftheadidx [string first\ |
| 368 |
$splitstr $errmsg $aftheadidx]] |
| 369 |
lassign [split [lindex [split $stackelt {"}] 1]] cmd1 cmd2 |
| 370 |
set cmdcaller [lindex [split [string range $stackelt [string last\ |
| 371 |
{(procedure } $stackelt] end] {"}] 1] |
| 372 |
if {$cmd1 eq {eval}} { |
| 373 |
set cmd1 $cmd2 |
| 374 |
} |
| 375 |
|
| 376 |
# filter out stack element referring to or called by an unknown |
| 377 |
# procedure (ie. a modulecmd.tcl internal procedure) |
| 378 |
if {$cmd1 ne $unkcmd && ($cmdcaller in $filtercmdlist || $cmd1 in\ |
| 379 |
$filtercmdlist)} { |
| 380 |
set errmsg [string replace $errmsg $aftheadidx [expr {[string first\ |
| 381 |
$splitstr $errmsg] + $splitstrlen - 1}]] |
| 382 |
} else { |
| 383 |
set internals 0 |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
# filter out modulecmd internal references at end of stack |
| 388 |
set internals 1 |
| 389 |
while {$internals} { |
| 390 |
set beffootidx [string last $splitstr $errmsg] |
| 391 |
set stackelt [string range $errmsg $beffootidx end] |
| 392 |
set cmd [lindex [split $stackelt {"}] 1] |
| 393 |
|
| 394 |
if {$cmd in $filtercmdendlist} { |
| 395 |
set errmsg [string replace $errmsg $beffootidx end] |
| 396 |
} else { |
| 397 |
set internals 0 |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
# filter out modulecmd internal references in middle of stack |
| 402 |
foreach filtercmdmid $filtercmdmidlist { |
| 403 |
set filterstartidx [string first \"$filtercmdmid\" $errmsg] |
| 404 |
if {$filterstartidx != -1} { |
| 405 |
set filterendidx [expr {[string first $splitstr $errmsg\ |
| 406 |
$filterstartidx] + [string length $splitstr] - 1}] |
| 407 |
set errmsg [string replace $errmsg $filterstartidx $filterendidx] |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
# replace error location at end of stack |
| 412 |
set lastnl [string last \n $errmsg] |
| 413 |
set lastline [string range $errmsg $lastnl+1 end] |
| 414 |
if {[string match { ("eval" body line*} $lastline]} { |
| 415 |
set errmsg [string replace $errmsg $lastnl $lastnl+[string length\ |
| 416 |
" (\"eval\" body line"] "\n (file \"$loc\" line"] |
| 417 |
} elseif {![string match { (file *} $lastline]} { |
| 418 |
# add error location at end of stack |
| 419 |
append errmsg "\n (file \"$loc\")" |
| 420 |
} |
| 421 |
|
| 422 |
return $errmsg |
| 423 |
} |
| 424 |
|
| 425 |
# Test if color is enabled and passed sgrkey is defined and not null |
| 426 |
proc isSgrkeyColored {sgrkey} { |
| 427 |
return [expr {[getConf color] && [info exists ::g_colors($sgrkey)] &&\ |
| 428 |
$::g_colors($sgrkey) ne {}}] |
| 429 |
} |
| 430 |
|
| 431 |
# Select Graphic Rendition of a string with passed sgr keys (if color enabled) |
| 432 |
proc sgr {keylist str {himatchmap {}} {othkeylist {}}} { |
| 433 |
if {[getConf color]} { |
| 434 |
set sgrreset 22 |
| 435 |
foreach sgrkey $keylist { |
| 436 |
if {[info exists ::g_colors($sgrkey)]} { |
| 437 |
# track color key that have been used |
| 438 |
if {![info exists ::g_used_colors($sgrkey)]} { |
| 439 |
set ::g_used_colors($sgrkey) 1 |
| 440 |
} |
| 441 |
if {[info exists sgrset]} { |
| 442 |
append sgrset {;} |
| 443 |
} |
| 444 |
append sgrset $::g_colors($sgrkey) |
| 445 |
# if render bold or faint just reset that attribute, not all |
| 446 |
if {$sgrreset != 0 && $sgrset != 1 && $sgrset != 2} { |
| 447 |
set sgrreset 0 |
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
if {![llength $othkeylist]} { |
| 452 |
# highlight matching substring |
| 453 |
if {[llength $himatchmap]} { |
| 454 |
set str [string map $himatchmap $str] |
| 455 |
} |
| 456 |
if {[info exists sgrset]} { |
| 457 |
set str "\033\[${sgrset}m$str\033\[${sgrreset}m" |
| 458 |
} |
| 459 |
} else { |
| 460 |
if {![info exists sgrset]} { |
| 461 |
set sgrset {} |
| 462 |
} else { |
| 463 |
append sgrset {;} |
| 464 |
} |
| 465 |
# determine each chunk where the other sgr keys apply |
| 466 |
set tagsgrlen [expr {int(ceil([string length $str]/[llength\ |
| 467 |
$othkeylist]))}] |
| 468 |
for {set i 0} {$i < [llength $othkeylist]} {incr i} { |
| 469 |
set idx [expr {$i*$tagsgrlen}] |
| 470 |
set sgrkey [lindex $othkeylist $i] |
| 471 |
lappend sgridxlist $idx $::g_colors($sgrkey) |
| 472 |
# track color key that have been used |
| 473 |
if {![info exists ::g_used_colors($sgrkey)]} { |
| 474 |
set ::g_used_colors($sgrkey) 1 |
| 475 |
} |
| 476 |
} |
| 477 |
# determine each chunk where the highlight applies |
| 478 |
set hiidxlist {} |
| 479 |
foreach {mstr sgrmstr} $himatchmap { |
| 480 |
set idx 0 |
| 481 |
while {$idx != -1} { |
| 482 |
if {[set idx [string first $mstr $str $idx]] != -1} { |
| 483 |
lappend hiidxlist $idx |
| 484 |
incr idx [string length $mstr] |
| 485 |
# add highlight end index unless if end of string |
| 486 |
if {$idx < [string length $str]} { |
| 487 |
lappend hiidxlist $idx |
| 488 |
} |
| 489 |
} |
| 490 |
} |
| 491 |
# no need to look at next match string if this one was found |
| 492 |
if {[llength $hiidxlist]} { |
| 493 |
break |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
# mix other sgr chunks with highlighted chunks to define sgr codes |
| 498 |
set i 0 |
| 499 |
set j 0 |
| 500 |
set sgridx [lindex $sgridxlist 0] |
| 501 |
set hiidx [lindex $hiidxlist 0] |
| 502 |
set hicur 0 |
| 503 |
set sgrcur {} |
| 504 |
set sgrrst {0;} |
| 505 |
while {$i < [llength $sgridxlist] || $j < [llength $hiidxlist]} { |
| 506 |
set sgrcode {} |
| 507 |
set cursgridx $sgridx |
| 508 |
# sgr chunk change |
| 509 |
if {$sgridx ne {} && ($hiidx eq {} || $sgridx <= $hiidx)} { |
| 510 |
incr i |
| 511 |
set sgrcur $sgrset[lindex $sgridxlist $i] |
| 512 |
set idx $sgridx |
| 513 |
if {$idx != 0} { |
| 514 |
append sgrcode $sgrrst |
| 515 |
} |
| 516 |
append sgrcode $sgrcur |
| 517 |
incr i |
| 518 |
set sgridx [lindex $sgridxlist $i] |
| 519 |
} |
| 520 |
# highlight change |
| 521 |
if {$hiidx ne {} && ($cursgridx eq {} || $hiidx <= $cursgridx)} { |
| 522 |
set idx $hiidx |
| 523 |
set hicur [expr {!$hicur}] |
| 524 |
if {$hicur} { |
| 525 |
if {$sgrcode ne {}} { |
| 526 |
append sgrcode {;} |
| 527 |
} |
| 528 |
append sgrcode $::g_colors(hi) |
| 529 |
# restore current sgr set to only clear highlight |
| 530 |
} elseif {$sgrcode eq {}} { |
| 531 |
append sgrcode $sgrrst $sgrcur |
| 532 |
} |
| 533 |
incr j |
| 534 |
set hiidx [lindex $hiidxlist $j] |
| 535 |
} elseif {$hicur} { |
| 536 |
append sgrcode {;} $::g_colors(hi) |
| 537 |
} |
| 538 |
lappend fullsgridxlist $idx $sgrcode |
| 539 |
} |
| 540 |
# reset sgr at end of string |
| 541 |
lappend fullsgridxlist [string length $str] 0 |
| 542 |
|
| 543 |
# apply defined sgr codes to the string |
| 544 |
set stridx 0 |
| 545 |
foreach {sgridx sgrcode} $fullsgridxlist { |
| 546 |
if {$sgridx != 0} { |
| 547 |
append sgrstr [string range $str $stridx $sgridx-1] |
| 548 |
} |
| 549 |
append sgrstr "\033\[${sgrcode}m" |
| 550 |
set stridx $sgridx |
| 551 |
} |
| 552 |
set str $sgrstr |
| 553 |
} |
| 554 |
} |
| 555 |
return $str |
| 556 |
} |
| 557 |
|
| 558 |
# Sort tags to return those matching defined sgr keys in a list up to a given |
| 559 |
# maxnb number and if tag not set to be displayed by its name. Other elements |
| 560 |
# are returned in a separate list |
| 561 |
proc getTagSgrForModname {keylist maxnb} { |
| 562 |
set sgrkeylist {} |
| 563 |
if {[getConf color]} { |
| 564 |
set otherlist {} |
| 565 |
foreach key $keylist { |
| 566 |
if {[info exists ::g_colors($key)] && ![info exists\ |
| 567 |
::g_tagColorName($key)] && [llength $sgrkeylist] < $maxnb} { |
| 568 |
lappend sgrkeylist $key |
| 569 |
} else { |
| 570 |
lappend otherlist $key |
| 571 |
} |
| 572 |
} |
| 573 |
} else { |
| 574 |
set otherlist $keylist |
| 575 |
} |
| 576 |
return [list $sgrkeylist $otherlist] |
| 577 |
} |
| 578 |
|
| 579 |
# save message if report is not yet initialized |
| 580 |
proc report {message {nonewline 0} {immed 0} {padnl 0}} { |
| 581 |
lappend ::errreport_buffer [list report $message $nonewline $immed $padnl] |
| 582 |
} |
| 583 |
|
| 584 |
# regular procedure to use once error report is initialized |
| 585 |
proc __report {message {nonewline 0} {immed 0} {padnl 0}} { |
| 586 |
# hold or print output |
| 587 |
if {!$immed && [depthState reportholdid] > 0} { |
| 588 |
lappend ::g_holdReport([currentState reportholdid]) [list report\ |
| 589 |
$message $nonewline $immed $padnl] |
| 590 |
} else { |
| 591 |
# produce blank line prior message if asked to |
| 592 |
if {[isStateDefined reportfd] && [isStateDefined report_sep_next]} { |
| 593 |
unsetState report_sep_next |
| 594 |
report [expr {[isStateEqual report_format json] ? {,} : {}}] |
| 595 |
} |
| 596 |
# prefix msg lines after first one with 2 spaces |
| 597 |
if {$padnl} { |
| 598 |
set first 1 |
| 599 |
foreach line [split $message \n] { |
| 600 |
if {$first} { |
| 601 |
set first 0 |
| 602 |
} else { |
| 603 |
append padmsg "\n " |
| 604 |
} |
| 605 |
append padmsg $line |
| 606 |
} |
| 607 |
set message $padmsg |
| 608 |
} |
| 609 |
|
| 610 |
# protect from issue with fd, just ignore it |
| 611 |
catch { |
| 612 |
if {$nonewline} { |
| 613 |
puts -nonewline [getState reportfd] $message |
| 614 |
} else { |
| 615 |
puts [getState reportfd] $message |
| 616 |
} |
| 617 |
} |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
# report error the correct way depending of its type |
| 622 |
proc reportIssue {issuetype issuemsg {issuefile {}}} { |
| 623 |
switch -- $issuetype { |
| 624 |
invalid { |
| 625 |
reportInternalBug $issuemsg $issuefile |
| 626 |
} |
| 627 |
default { |
| 628 |
reportError $issuemsg |
| 629 |
} |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
# report defined command (used in display evaluation mode) |
| 634 |
proc reportCmd {cmd args} { |
| 635 |
# use Tcl native string representation of list |
| 636 |
if {$cmd eq {-nativeargrep}} { |
| 637 |
set cmd [lindex $args 0] |
| 638 |
set cmdargs [lrange $args 1 end] |
| 639 |
} else { |
| 640 |
set cmdargs [listTo tcl $args 0] |
| 641 |
} |
| 642 |
set extratab [expr {[string length $cmd] < 8 ? "\t" : {}}] |
| 643 |
report [sgr cm $cmd]$extratab\t$cmdargs |
| 644 |
|
| 645 |
# empty string returns if command result is another command input |
| 646 |
return {} |
| 647 |
} |
| 648 |
|
| 649 |
# report defined command (called as an execution trace) |
| 650 |
proc reportCmdTrace {cmdstring args} { |
| 651 |
reportCmd {*}$cmdstring |
| 652 |
} |
| 653 |
|
| 654 |
proc reportVersion {} { |
| 655 |
report {Modules Release @MODULES_RELEASE@@MODULES_BUILD@\ |
| 656 |
(@MODULES_BUILD_DATE@)} |
| 657 |
} |
| 658 |
|
| 659 |
proc reportName {} { |
| 660 |
report Modules |
| 661 |
} |
| 662 |
|
| 663 |
# disable error reporting (non-critical report only) unless debug enabled |
| 664 |
proc inhibitErrorReport {} { |
| 665 |
if {![isVerbosityLevel trace]} { |
| 666 |
setState inhibit_errreport 1 |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
proc initProcReportTrace {type prc} { |
| 671 |
##nagelfar ignore #7 Non static subcommand |
| 672 |
if {[isVerbosityLevel debug] && [getState timer]} { |
| 673 |
# time execution of procedure instead of regular debug report |
| 674 |
trace $type execution $prc enter reportTimerExecEnter |
| 675 |
trace $type execution $prc leave reportTimerExecLeave |
| 676 |
} elseif {[isVerbosityLevel debug2]} { |
| 677 |
# trace each procedure call |
| 678 |
trace $type execution $prc enter reportTraceExecEnter |
| 679 |
} |
| 680 |
} |
| 681 |
|
| 682 |
# init error report and output buffered messages |
| 683 |
proc initErrorReport {} { |
| 684 |
# ensure init is done only once |
| 685 |
if {![isStateDefined init_error_report]} { |
| 686 |
setState init_error_report 1 |
| 687 |
|
| 688 |
# ask for color init now as debug mode has already fire lines to render |
| 689 |
# and we want them to be reported first (not the color init lines) |
| 690 |
if {[isVerbosityLevel debug]} { |
| 691 |
getConf color |
| 692 |
} |
| 693 |
|
| 694 |
# trigger pager start if something needs to be printed, to guaranty |
| 695 |
# reportDebug calls during pager start are processed in buffer mode |
| 696 |
if {[isVerbosityLevel debug]} { |
| 697 |
getState reportfd |
| 698 |
} |
| 699 |
|
| 700 |
# only report timing information in debug mode if timer mode is enabled |
| 701 |
if {[isVerbosityLevel debug] && ![getState timer]} { |
| 702 |
# replace report procedures used to buffer messages until error |
| 703 |
# report being initialized by regular report procedures |
| 704 |
# delete initial reportDebug proc after getState which needs it |
| 705 |
rename ::reportDebug {} |
| 706 |
rename ::__reportDebug ::reportDebug |
| 707 |
} else { |
| 708 |
rename ::reportDebug {} |
| 709 |
# set a disabled version if debug is disabled |
| 710 |
rename ::__reportDebugNop ::reportDebug |
| 711 |
} |
| 712 |
rename ::reportError {} |
| 713 |
rename ::__reportError ::reportError |
| 714 |
rename ::reportErrorAndExit {} |
| 715 |
rename ::__reportErrorAndExit ::reportErrorAndExit |
| 716 |
rename ::reportSeparateNextContent {} |
| 717 |
rename ::__reportSeparateNextContent ::reportSeparateNextContent |
| 718 |
rename ::report {} |
| 719 |
rename ::__report ::report |
| 720 |
|
| 721 |
# setup traces for either debug or timer reports |
| 722 |
if {[isVerbosityLevel debug] && [getState timer] || [isVerbosityLevel\ |
| 723 |
debug2]} { |
| 724 |
# list of core procedures to exclude from tracing |
| 725 |
set excl_prc_list [list report reportDebug reportFlush reportTimer\ |
| 726 |
reportTraceExecEnter reportTimerExecEnter reportTimerExecLeave\ |
| 727 |
initProcReportTrace isVerbosityLevel reportSeparateNextContent\ |
| 728 |
getState setState unsetState lappendState lpopState currentState\ |
| 729 |
depthState isStateDefined isStateEqual sgr getConf setConf\ |
| 730 |
unsetConf lappendConf getCallingProcName isEnvVarDefined\ |
| 731 |
envVarEquals log getConfList] |
| 732 |
|
| 733 |
foreach prc [info procs] { |
| 734 |
if {$prc ni $excl_prc_list} { |
| 735 |
initProcReportTrace add $prc |
| 736 |
} |
| 737 |
} |
| 738 |
} |
| 739 |
|
| 740 |
# now error report is init output every message saved in buffer; first |
| 741 |
# message will trigger message paging configuration and startup unless |
| 742 |
# already done if debug mode enabled |
| 743 |
foreach errreport $::errreport_buffer { |
| 744 |
{*}$errreport |
| 745 |
} |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
# drop or report held messages |
| 750 |
proc releaseHeldReport {args} { |
| 751 |
foreach {holdid action} $args { |
| 752 |
if {[info exists ::g_holdReport($holdid)]} { |
| 753 |
if {$action eq {report}} { |
| 754 |
foreach repcall $::g_holdReport($holdid) { |
| 755 |
{*}$repcall |
| 756 |
} |
| 757 |
} |
| 758 |
unset ::g_holdReport($holdid) |
| 759 |
} |
| 760 |
# also drop reported tag of conflict error |
| 761 |
if {[info exists ::g_holdReportConflict($holdid)]} { |
| 762 |
if {$action eq {drop}} { |
| 763 |
foreach {evalid drop_mod_list} $::g_holdReportConflict($holdid) { |
| 764 |
lassign [getDiffBetweenList $::report_conflict($evalid)\ |
| 765 |
$drop_mod_list] ::report_conflict($evalid) |
| 766 |
} |
| 767 |
} |
| 768 |
unset ::g_holdReportConflict($holdid) |
| 769 |
} |
| 770 |
# also drop failed module evaluation to get their failure information |
| 771 |
# if later retried |
| 772 |
if {[info exists ::g_holdModuleFailedEval($holdid)]} { |
| 773 |
if {$action eq {drop}} { |
| 774 |
foreach {evalid failed_context failed_mod}\ |
| 775 |
$::g_holdModuleFailedEval($holdid) { |
| 776 |
set failed_eval_list $::g_moduleFailedEval($evalid) |
| 777 |
for {set i 0} {$i < [llength $failed_eval_list]} {incr i} { |
| 778 |
if {[lindex $failed_eval_list $i] eq $failed_context &&\ |
| 779 |
[lindex $failed_eval_list $i+1] eq $failed_mod} { |
| 780 |
set failed_eval_list [lreplace $failed_eval_list $i $i+1] |
| 781 |
break |
| 782 |
} |
| 783 |
} |
| 784 |
set ::g_moduleFailedEval($evalid) $failed_eval_list |
| 785 |
} |
| 786 |
} |
| 787 |
unset ::g_holdModuleFailedEval($holdid) |
| 788 |
} |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
# final message output and reportfd flush and close |
| 793 |
proc reportFlush {} { |
| 794 |
# report execution time if asked |
| 795 |
if {[getState timer]} { |
| 796 |
reportSeparateNextContent |
| 797 |
reportTimer {Total execution took} {%.3f ms} $::timer_start [clock\ |
| 798 |
microseconds] |
| 799 |
} |
| 800 |
|
| 801 |
# finish output document if json format enabled |
| 802 |
if {[isStateEqual report_format json]} { |
| 803 |
# render error messages all together |
| 804 |
if {[info exists ::g_report_erralist]} { |
| 805 |
# ignite report first to get eventual error message from report |
| 806 |
# initialization in order 'foreach' got all messages prior firing |
| 807 |
report "\"errors\": \[" 1 |
| 808 |
foreach {sev msg} $::g_report_erralist { |
| 809 |
# split message in lines |
| 810 |
lappend dispmsglist "\n{ \"severity\": \"$sev\", \"message\": \[\ |
| 811 |
\"[join [split [charEscaped $msg \"] \n] {", "}]\" \] }" |
| 812 |
} |
| 813 |
report "[join $dispmsglist ,] \]" |
| 814 |
} |
| 815 |
# inhibit next content separator if output is ending |
| 816 |
unsetState report_sep_next |
| 817 |
report \} |
| 818 |
} |
| 819 |
|
| 820 |
# close pager if enabled |
| 821 |
if {[isStateDefined reportfd] && ![isStateEqual reportfd stderr]} { |
| 822 |
catch {flush [getState reportfd]} |
| 823 |
catch {close [getState reportfd]} |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
proc logEvent {event args} { |
| 828 |
if {$event in [getConfList logged_events]} { |
| 829 |
set log_info_list [list user [getState username] {*}$args] |
| 830 |
set log_formatted_list {} |
| 831 |
foreach {key val} $log_info_list { |
| 832 |
lappend log_formatted_list "$key=\"$val\"" |
| 833 |
} |
| 834 |
set log_message [join $log_formatted_list] |
| 835 |
log $log_message |
| 836 |
} |
| 837 |
} |
| 838 |
|
| 839 |
proc log {log_message} { |
| 840 |
lappend ::g_log_msg_list $log_message |
| 841 |
} |
| 842 |
|
| 843 |
# send messages to log |
| 844 |
proc logFlush {} { |
| 845 |
# logger pipe is started only if enabled and some msgs need to be logged |
| 846 |
set logfd [getState logfd] |
| 847 |
|
| 848 |
# logging only occurs from this procedure with is run during termination |
| 849 |
if {[string length $logfd]} { |
| 850 |
if {[catch { |
| 851 |
foreach log_msg $::g_log_msg_list { |
| 852 |
puts $logfd $log_msg |
| 853 |
} |
| 854 |
flush $logfd |
| 855 |
close $logfd |
| 856 |
} errMsg]} { |
| 857 |
reportWarning {Issue occurred when logging information} |
| 858 |
} |
| 859 |
} |
| 860 |
} |
| 861 |
|
| 862 |
# check if element passed as argument (corresponding to a kind of information) |
| 863 |
# should be part of output content |
| 864 |
proc isEltInReport {elt {retifnotdef 1}} { |
| 865 |
# get config name relative to current sub-command and output format |
| 866 |
set conf [currentState commandname] |
| 867 |
if {[getState report_format] ne {regular}} { |
| 868 |
append conf _[getState report_format] |
| 869 |
} |
| 870 |
append conf _output |
| 871 |
set arrname ::g_$conf |
| 872 |
##nagelfar vartype arrname varName |
| 873 |
|
| 874 |
if {[info exists ::g_config_defs($conf)]} { |
| 875 |
# build value cache if it does not exist yet |
| 876 |
if {![array exists $arrname]} { |
| 877 |
array set $arrname {} |
| 878 |
foreach confelt [getConfList $conf] { |
| 879 |
##nagelfar ignore Suspicious variable name |
| 880 |
set ${arrname}($confelt) 1 |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
# check if elt is marked to be included in output |
| 885 |
##nagelfar ignore Suspicious variable name |
| 886 |
return [info exists ${arrname}($elt)] |
| 887 |
} else { |
| 888 |
# return $retifnotdef (ok by default) in case no config option |
| 889 |
# corresponds to the current module sub-command and output format |
| 890 |
return $retifnotdef |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
proc registerModuleDesignation {evalid mod vrlist taglist} { |
| 895 |
set ::g_moduleDesgination($evalid) [list $mod $vrlist $taglist] |
| 896 |
} |
| 897 |
|
| 898 |
proc getModuleFromEvalId {evalid} { |
| 899 |
if {[info exists ::g_moduleDesgination($evalid)]} { |
| 900 |
return [lindex $::g_moduleDesgination($evalid) 0] |
| 901 |
} |
| 902 |
} |
| 903 |
|
| 904 |
proc getModuleDesignation {from {mod {}} {sgr 1}} { |
| 905 |
# fetch module name version and variants from specified context |
| 906 |
switch -- $from { |
| 907 |
spec { |
| 908 |
set moddesig [getModuleNameAndVersFromVersSpec $mod] |
| 909 |
set vrlist [getVariantList $mod 7 0 1] |
| 910 |
set taglist {} |
| 911 |
} |
| 912 |
loaded { |
| 913 |
set moddesig $mod |
| 914 |
set vrlist [getVariantList $mod 7] |
| 915 |
set taglist {} |
| 916 |
} |
| 917 |
default { |
| 918 |
# fetch information from passed evaluation id |
| 919 |
if {[info exists ::g_moduleDesgination($from)]} { |
| 920 |
lassign $::g_moduleDesgination($from) moddesig vrlist taglist |
| 921 |
# if not found, use passed spec to compute designation |
| 922 |
} else { |
| 923 |
set moddesig [getModuleNameAndVersFromVersSpec $mod] |
| 924 |
set vrlist [getVariantList $mod 7 0 1] |
| 925 |
set taglist [getExportTagList $mod] |
| 926 |
} |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
# build module designation |
| 931 |
switch -- $sgr { |
| 932 |
2 { |
| 933 |
set vrsgr va |
| 934 |
set himatchmap [prepareMapToHightlightSubstr $moddesig] |
| 935 |
|
| 936 |
set showtags 1 |
| 937 |
# prepare list of tag abbreviations that can be substituted and list |
| 938 |
# of tags whose name should be colored |
| 939 |
getConf tag_abbrev |
| 940 |
getConf tag_color_name |
| 941 |
# abbreviate tags |
| 942 |
set taglist [abbrevTagList $taglist] |
| 943 |
} |
| 944 |
1 { |
| 945 |
set vrsgr {se va} |
| 946 |
set himatchmap {} |
| 947 |
set showtags 0 |
| 948 |
} |
| 949 |
0 { |
| 950 |
set vrsgr {} |
| 951 |
set himatchmap {} |
| 952 |
set showtags 0 |
| 953 |
} |
| 954 |
} |
| 955 |
lassign [formatListEltToDisplay $moddesig {} {} {} {} 0 0 $taglist\ |
| 956 |
$showtags $vrlist $vrsgr 1 $himatchmap] disp dispsgr displen |
| 957 |
|
| 958 |
return $dispsgr |
| 959 |
} |
| 960 |
|
| 961 |
# |
| 962 |
# Helper procedures to format various messages |
| 963 |
# |
| 964 |
|
| 965 |
proc getHintUnFirstMsg {modlist} { |
| 966 |
return "HINT: Might try \"module unload [join $modlist]\" first." |
| 967 |
} |
| 968 |
|
| 969 |
proc getHintLoFirstMsg {modlist} { |
| 970 |
if {[llength $modlist] > 1} { |
| 971 |
set oneof {at least one of } |
| 972 |
set mod modules |
| 973 |
} else { |
| 974 |
set oneof {} |
| 975 |
set mod module |
| 976 |
} |
| 977 |
return "HINT: ${oneof}the following $mod must be loaded first: [join\ |
| 978 |
$modlist]" |
| 979 |
} |
| 980 |
|
| 981 |
proc getErrConflictMsg {conlist} { |
| 982 |
return "Module cannot be loaded due to a conflict.\n[getHintUnFirstMsg\ |
| 983 |
$conlist]" |
| 984 |
} |
| 985 |
|
| 986 |
proc getErrPrereqMsg {prelist {load 1} {is_path_specific 0}} { |
| 987 |
if {$load} { |
| 988 |
foreach pre $prelist { |
| 989 |
lappend predesiglist [getModuleDesignation spec $pre] |
| 990 |
} |
| 991 |
lassign [list {} missing [getHintLoFirstMsg $predesiglist]] un miss\ |
| 992 |
hintmsg |
| 993 |
} else { |
| 994 |
##nagelfar ignore Found constant |
| 995 |
lassign [list un a [getHintUnFirstMsg $prelist]] un miss hintmsg |
| 996 |
} |
| 997 |
set path_specific_msg [expr {$is_path_specific ? [getSpecificPathMsg] :\ |
| 998 |
{}}] |
| 999 |
return "Module cannot be ${un}loaded due to $miss\ |
| 1000 |
prereq$path_specific_msg.\n$hintmsg" |
| 1001 |
} |
| 1002 |
|
| 1003 |
proc getErrReqLoMsg {prelist {is_path_specific 0}} { |
| 1004 |
foreach pre $prelist { |
| 1005 |
lappend predesiglist [getModuleDesignation spec $pre] |
| 1006 |
} |
| 1007 |
set path_specific_msg [expr {$is_path_specific ? [getSpecificPathMsg] :\ |
| 1008 |
{}}] |
| 1009 |
return "Load of requirement [join $predesiglist { or }]$path_specific_msg\ |
| 1010 |
failed" |
| 1011 |
} |
| 1012 |
|
| 1013 |
proc getReqNotLoadedMsg {prelist {is_path_specific 0}} { |
| 1014 |
foreach pre $prelist { |
| 1015 |
lappend predesiglist [getModuleDesignation spec $pre] |
| 1016 |
} |
| 1017 |
set path_specific_msg [expr {$is_path_specific ? [getSpecificPathMsg] :\ |
| 1018 |
{}}] |
| 1019 |
return "Requirement [join $predesiglist { or }]$path_specific_msg is not\ |
| 1020 |
loaded" |
| 1021 |
} |
| 1022 |
|
| 1023 |
proc getSpecificPathMsg {} { |
| 1024 |
return { (specific path)} |
| 1025 |
} |
| 1026 |
|
| 1027 |
proc getKindModuleBeStateMsg {kind mod_list state} { |
| 1028 |
set is [expr {[llength $mod_list] > 1 ? {are} : {is}}] |
| 1029 |
foreach mod $mod_list { |
| 1030 |
lappend mod_desig_list [getModuleDesignation loaded $mod] |
| 1031 |
} |
| 1032 |
return "$kind [join $mod_desig_list { and }] $is $state" |
| 1033 |
} |
| 1034 |
|
| 1035 |
proc getDepLoadedMsg {pre_mod_list} { |
| 1036 |
return [getKindModuleBeStateMsg Dependent $pre_mod_list loaded] |
| 1037 |
} |
| 1038 |
|
| 1039 |
proc getDepLoadingMsg {pre_mod_list} { |
| 1040 |
return [getKindModuleBeStateMsg Dependent $pre_mod_list loading] |
| 1041 |
} |
| 1042 |
|
| 1043 |
proc getErrConUnMsg {conlist} { |
| 1044 |
set condesiglist {} |
| 1045 |
foreach con $conlist { |
| 1046 |
lappend condesiglist [getModuleDesignation spec $con] |
| 1047 |
} |
| 1048 |
return "Unload of conflicting [join $condesiglist { and }] failed" |
| 1049 |
} |
| 1050 |
|
| 1051 |
proc getConLoadedMsg {con_mod_list} { |
| 1052 |
return [getKindModuleBeStateMsg Conflicting $con_mod_list loaded] |
| 1053 |
} |
| 1054 |
|
| 1055 |
proc getConLoadingMsg {con_mod_list} { |
| 1056 |
return [getKindModuleBeStateMsg Conflicting $con_mod_list loading] |
| 1057 |
} |
| 1058 |
|
| 1059 |
proc getPresentConflictErrorMsg {curmodnamevr con_mod_list is_loading} { |
| 1060 |
if {[isModuleEvaluated any $curmodnamevr {} {*}$con_mod_list] || [getState\ |
| 1061 |
force]} { |
| 1062 |
return [expr {$is_loading ? [getConLoadingMsg $con_mod_list] :\ |
| 1063 |
[getConLoadedMsg $con_mod_list]}] |
| 1064 |
} else { |
| 1065 |
return [getErrConflictMsg $con_mod_list] |
| 1066 |
} |
| 1067 |
} |
| 1068 |
|
| 1069 |
proc getForbiddenMsg {mod fpmod} { |
| 1070 |
set msg "Access to module [getModuleDesignation spec $mod 2] is denied" |
| 1071 |
set extramsg [getModuleTagProp $mod $fpmod forbidden message] |
| 1072 |
if {$extramsg ne {}} { |
| 1073 |
append msg \n$extramsg |
| 1074 |
} |
| 1075 |
return $msg |
| 1076 |
} |
| 1077 |
|
| 1078 |
proc getNearlyForbiddenMsg {mod fpmod} { |
| 1079 |
set after [getModuleTagProp $mod $fpmod nearly-forbidden after] |
| 1080 |
set msg "Access to module will be denied starting '$after'" |
| 1081 |
set extramsg [getModuleTagProp $mod $fpmod nearly-forbidden message] |
| 1082 |
if {$extramsg ne {}} { |
| 1083 |
append msg \n$extramsg |
| 1084 |
} |
| 1085 |
return $msg |
| 1086 |
} |
| 1087 |
|
| 1088 |
proc getWarningMsg {mod fpmod} { |
| 1089 |
return [getModuleTagProp $mod $fpmod warning message] |
| 1090 |
} |
| 1091 |
|
| 1092 |
proc getStickyUnloadMsg {{tag sticky}} { |
| 1093 |
return "Unload of $tag module skipped" |
| 1094 |
} |
| 1095 |
|
| 1096 |
proc getStickyForcedUnloadMsg {} { |
| 1097 |
return {Unload of sticky module forced} |
| 1098 |
} |
| 1099 |
|
| 1100 |
proc getModWithAltVrIsLoadedMsg {mod is_loading} { |
| 1101 |
set vrdesiglist {} |
| 1102 |
foreach vr [getVariantList $mod 1] { |
| 1103 |
lappend vrdesiglist [sgr va $vr] |
| 1104 |
} |
| 1105 |
set state [expr {$is_loading ? {loading} : {loaded}}] |
| 1106 |
return "Variant [sgr se "\{"][join $vrdesiglist [sgr se :]][sgr se "\}"]\ |
| 1107 |
is already $state" |
| 1108 |
} |
| 1109 |
|
| 1110 |
proc getModFromDiffPathIsLoadedMsg {} { |
| 1111 |
return {Module already loaded from a different modulepath} |
| 1112 |
} |
| 1113 |
|
| 1114 |
proc getEmptyNameMsg {type} { |
| 1115 |
return "Invalid empty $type name" |
| 1116 |
} |
| 1117 |
|
| 1118 |
# |
| 1119 |
# Stack of message recording/eval unique identifiers |
| 1120 |
# |
| 1121 |
|
| 1122 |
proc pushMsgRecordId {recid {setmsgid 1}} { |
| 1123 |
lappendState evalid $recid |
| 1124 |
if {$setmsgid} { |
| 1125 |
lappendState msgrecordid $recid |
| 1126 |
} |
| 1127 |
} |
| 1128 |
|
| 1129 |
proc popMsgRecordId {{setmsgid 1}} { |
| 1130 |
lpopState evalid |
| 1131 |
if {$setmsgid} { |
| 1132 |
lpopState msgrecordid |
| 1133 |
} |
| 1134 |
} |
| 1135 |
|
| 1136 |
proc clearAllMsgRecordId {} { |
| 1137 |
unsetState evalid |
| 1138 |
unsetState msgrecordid |
| 1139 |
} |
| 1140 |
|
| 1141 |
# |
| 1142 |
# Format output text |
| 1143 |
# |
| 1144 |
|
| 1145 |
# format an element with its syms for display in a list |
| 1146 |
proc formatListEltToDisplay {elt eltsgr eltsuffix sym_list symsgr show_syms\ |
| 1147 |
sgrdef tag_list show_tags vr_list vrsgr show_vrs {himatchmap {}}\ |
| 1148 |
{himatcharrvrmap {}} {himatcharrvrvalmap {}}} { |
| 1149 |
# fetch sgr codes from tags to apply directly on main element |
| 1150 |
if {$show_tags && [llength $tag_list]} { |
| 1151 |
# if more codes than character in elt, additional codes apply to the |
| 1152 |
# side tag list |
| 1153 |
lassign [getTagSgrForModname $tag_list [string length $elt]] tagsgrlist\ |
| 1154 |
tag_list |
| 1155 |
} else { |
| 1156 |
set tagsgrlist {} |
| 1157 |
} |
| 1158 |
# display default sym graphically over element name |
| 1159 |
if {$show_syms} { |
| 1160 |
if {[set defidx [lsearch -exact $sym_list default]] != -1 && $sgrdef} { |
| 1161 |
set sym_list [lreplace $sym_list $defidx $defidx] |
| 1162 |
lappend eltsgrlist de |
| 1163 |
} |
| 1164 |
} |
| 1165 |
|
| 1166 |
set displen 0 |
| 1167 |
set disp $elt |
| 1168 |
lappend eltsgrlist $eltsgr |
| 1169 |
set dispsgr [sgr $eltsgrlist $elt $himatchmap $tagsgrlist] |
| 1170 |
# enclose name between quotes if a space is found |
| 1171 |
if {[string first { } $elt] != -1} { |
| 1172 |
incr displen 2 |
| 1173 |
set dispsgr '$dispsgr' |
| 1174 |
} |
| 1175 |
# append suffix |
| 1176 |
append disp $eltsuffix |
| 1177 |
append dispsgr $eltsuffix |
| 1178 |
|
| 1179 |
# format variant list if any |
| 1180 |
if {$show_vrs && [llength $vr_list]} { |
| 1181 |
array set himatchvrvalarr $himatcharrvrvalmap |
| 1182 |
array set himatchvrarr $himatcharrvrmap |
| 1183 |
set commasgr [sgr se ,] |
| 1184 |
set vrssgr "[sgr se \{]" |
| 1185 |
set vrs \{ |
| 1186 |
foreach vrspec $vr_list { |
| 1187 |
lassign $vrspec vrname vrnameset vrvalues vrdflidx vrloadedidx\ |
| 1188 |
loadedsgrkey |
| 1189 |
array unset vrvalsgridx |
| 1190 |
# apply sgr to default and loaded variant value |
| 1191 |
if {$vrdflidx != -1} { |
| 1192 |
lappend vrvalsgridx($vrdflidx) de |
| 1193 |
} |
| 1194 |
if {$vrloadedidx != -1} { |
| 1195 |
lappend vrvalsgridx($vrloadedidx) $loadedsgrkey |
| 1196 |
} |
| 1197 |
set vrsgrvalues $vrvalues |
| 1198 |
foreach vrvalidx [array names vrvalsgridx] { |
| 1199 |
lset vrsgrvalues $vrvalidx [sgr $vrvalsgridx($vrvalidx) [lindex\ |
| 1200 |
$vrvalues $vrvalidx]] |
| 1201 |
} |
| 1202 |
if {[info exists notfirstvr]} { |
| 1203 |
set colonsgr [sgr se :] |
| 1204 |
append vrssgr $colonsgr |
| 1205 |
append vrs : |
| 1206 |
} else { |
| 1207 |
set notfirstvr 1 |
| 1208 |
} |
| 1209 |
# highlight variant if corresponds to one set in query |
| 1210 |
if {[info exists himatchvrarr($vrname)]} { |
| 1211 |
set hivrmap $himatchvrarr($vrname) |
| 1212 |
set hivrvalmap $himatchvrvalarr($vrname) |
| 1213 |
} else { |
| 1214 |
set hivrmap {} |
| 1215 |
set hivrvalmap {} |
| 1216 |
} |
| 1217 |
if {[string length $vrnameset]} { |
| 1218 |
append vrssgr [sgr $vrsgr $vrnameset $hivrmap] |
| 1219 |
} |
| 1220 |
append vrssgr [sgr $vrsgr [lindex $vrsgrvalues 0] $hivrvalmap] |
| 1221 |
foreach vrvalue [lrange $vrsgrvalues 1 end] { |
| 1222 |
append vrssgr $commasgr[sgr $vrsgr $vrvalue $hivrvalmap] |
| 1223 |
} |
| 1224 |
append vrs $vrnameset[join $vrvalues :] |
| 1225 |
} |
| 1226 |
append vrssgr [sgr se \}] |
| 1227 |
append vrs \} |
| 1228 |
append dispsgr $vrssgr |
| 1229 |
append disp $vrs |
| 1230 |
} |
| 1231 |
|
| 1232 |
# format remaining sym list |
| 1233 |
if {$show_syms && [llength $sym_list]} { |
| 1234 |
# track if a symbol has been reported excluding sym for alias '@' |
| 1235 |
if {![info exists ::g_used_sym_nocolor] && ([llength $sym_list] > 1 || |
| 1236 |
[lindex $sym_list 0] ne {@})} { |
| 1237 |
set ::g_used_sym_nocolor 1 |
| 1238 |
} |
| 1239 |
append disp "([join $sym_list :])" |
| 1240 |
set symssgr [sgr se (] |
| 1241 |
foreach sym $sym_list { |
| 1242 |
if {[info exists notfirstsym]} { |
| 1243 |
if {![info exists colonsgr]} { |
| 1244 |
set colonsgr [sgr se :] |
| 1245 |
} |
| 1246 |
append symssgr $colonsgr |
| 1247 |
} else { |
| 1248 |
set notfirstsym 1 |
| 1249 |
} |
| 1250 |
append symssgr [sgr $symsgr $sym] |
| 1251 |
} |
| 1252 |
append symssgr [sgr se )] |
| 1253 |
append dispsgr $symssgr |
| 1254 |
} |
| 1255 |
|
| 1256 |
# format tag list if any remaining |
| 1257 |
if {$show_tags && [llength $tag_list]} { |
| 1258 |
append disp " <[join $tag_list :]>" |
| 1259 |
set tagssgr " [sgr se <]" |
| 1260 |
foreach tag $tag_list { |
| 1261 |
# track tag name or abbreviation that have been used |
| 1262 |
if {![info exists ::g_used_tags($tag)]} { |
| 1263 |
set ::g_used_tags($tag) 1 |
| 1264 |
} |
| 1265 |
if {[info exists notfirsttag]} { |
| 1266 |
if {![info exists colonsgr]} { |
| 1267 |
set colonsgr [sgr se :] |
| 1268 |
} |
| 1269 |
append tagssgr $colonsgr |
| 1270 |
} else { |
| 1271 |
set notfirsttag 1 |
| 1272 |
} |
| 1273 |
# try to sgr in case a code apply to the tag |
| 1274 |
append tagssgr [sgr $tag $tag] |
| 1275 |
} |
| 1276 |
append tagssgr [sgr se >] |
| 1277 |
append dispsgr $tagssgr |
| 1278 |
} |
| 1279 |
|
| 1280 |
# compute length |
| 1281 |
incr displen [string length $disp] |
| 1282 |
|
| 1283 |
return [list $disp $dispsgr $displen] |
| 1284 |
} |
| 1285 |
|
| 1286 |
# format an element with its syms for a long/detailed display in a list |
| 1287 |
proc formatListEltToLongDisplay {elt eltsgr eltsuffix sym_list symsgr mtime\ |
| 1288 |
sgrdef {himatchmap {}}} { |
| 1289 |
# display default sym graphically over element name |
| 1290 |
if {[set defidx [lsearch -exact $sym_list default]] != -1 && $sgrdef} { |
| 1291 |
set sym_list [lreplace $sym_list $defidx $defidx] |
| 1292 |
lappend eltsgrlist de |
| 1293 |
} |
| 1294 |
lappend eltsgrlist $eltsgr |
| 1295 |
|
| 1296 |
set displen 0 |
| 1297 |
set disp $elt |
| 1298 |
set dispsgr [sgr $eltsgrlist $elt $himatchmap] |
| 1299 |
# enclose name between quotes if a space is found |
| 1300 |
if {[string first { } $elt] != -1} { |
| 1301 |
incr displen 2 |
| 1302 |
set dispsgr '$dispsgr' |
| 1303 |
} |
| 1304 |
# append suffix |
| 1305 |
append disp $eltsuffix |
| 1306 |
append dispsgr $eltsuffix |
| 1307 |
|
| 1308 |
# compute length |
| 1309 |
incr displen [string length $disp] |
| 1310 |
|
| 1311 |
# format remaining sym list |
| 1312 |
if {[llength $sym_list]} { |
| 1313 |
set symslen [string length [join $sym_list :]] |
| 1314 |
foreach sym $sym_list { |
| 1315 |
if {![info exists colonsgr]} { |
| 1316 |
set colonsgr [sgr se :] |
| 1317 |
} else { |
| 1318 |
append symssgr $colonsgr |
| 1319 |
} |
| 1320 |
append symssgr [sgr $symsgr $sym] |
| 1321 |
} |
| 1322 |
} else { |
| 1323 |
set symssgr {} |
| 1324 |
set symslen 0 |
| 1325 |
} |
| 1326 |
set nbws1 [expr {40 - $displen}] |
| 1327 |
set nbws2 [expr {$nbws1 < 0 ? 20 - $symslen + $nbws1 : 20 - $symslen}] |
| 1328 |
return [list $disp $dispsgr[string repeat { } $nbws1]$symssgr[string\ |
| 1329 |
repeat { } $nbws2]$mtime $displen] |
| 1330 |
} |
| 1331 |
|
| 1332 |
proc formatArrayValToJson {vallist} { |
| 1333 |
return [expr {[llength $vallist] ? "\[ \"[join $vallist {", "}]\" \]" :\ |
| 1334 |
{[]}}] |
| 1335 |
} |
| 1336 |
|
| 1337 |
proc formatObjectValToJson {objlist} { |
| 1338 |
foreach {key val isbool} $objlist { |
| 1339 |
if {[info exists disp]} { |
| 1340 |
append disp {, } |
| 1341 |
} |
| 1342 |
append disp "\"$key\": " |
| 1343 |
if {$isbool} { |
| 1344 |
append disp [expr {$val ? {true} : {false}}] |
| 1345 |
} else { |
| 1346 |
append disp "\"$val\"" |
| 1347 |
} |
| 1348 |
} |
| 1349 |
##nagelfar ignore Bad expression |
| 1350 |
return [expr {[info exists disp] ? "{ $disp }" : "{}"}] |
| 1351 |
} |
| 1352 |
|
| 1353 |
# format an element with its syms for a json display in a list |
| 1354 |
proc formatListEltToJsonDisplay {elt args} { |
| 1355 |
set disp "\"$elt\": \{ \"name\": \"$elt\"" |
| 1356 |
foreach {key vtype val show} $args { |
| 1357 |
if {!$show} { |
| 1358 |
continue |
| 1359 |
} |
| 1360 |
append disp ", \"$key\": " |
| 1361 |
switch -- $vtype { |
| 1362 |
a {append disp [formatArrayValToJson $val]} |
| 1363 |
o {append disp [formatObjectValToJson $val]} |
| 1364 |
s {append disp "\"$val\""} |
| 1365 |
} |
| 1366 |
} |
| 1367 |
append disp "\}" |
| 1368 |
|
| 1369 |
return $disp |
| 1370 |
} |
| 1371 |
|
| 1372 |
# Prepare a map list to translate later on a substring in its highlighted |
| 1373 |
# counterpart. Translate substring into all module it specifies in case of an |
| 1374 |
# advanced version specification. Each string obtained is right trimmed from |
| 1375 |
# wildcard. No highlight is set for strings still containing wildcard chars |
| 1376 |
# after right trim operation. No highlist map is returned at all if highlight |
| 1377 |
# rendering is disabled. |
| 1378 |
proc prepareMapToHightlightSubstr {args} { |
| 1379 |
set maplist {} |
| 1380 |
if {[sgr hi {}] ne {}} { |
| 1381 |
foreach substr $args { |
| 1382 |
foreach m [getAllModulesFromVersSpec $substr] { |
| 1383 |
set m [string trimright $m {*?}] |
| 1384 |
if {$m ne {} && [string first * $m] == -1 && [string first ? $m]\ |
| 1385 |
== -1} { |
| 1386 |
lappend maplist $m [sgr hi $m] |
| 1387 |
} |
| 1388 |
} |
| 1389 |
} |
| 1390 |
} |
| 1391 |
return $maplist |
| 1392 |
} |
| 1393 |
|
| 1394 |
# Specific highlight translation map for variant name and value |
| 1395 |
proc prepareMapToHightlightVariant {args} { |
| 1396 |
if {[sgr hi {}] ne {}} { |
| 1397 |
foreach modspec $args { |
| 1398 |
foreach vrspec [getVariantListFromVersSpec $modspec] { |
| 1399 |
set vrvalues [lassign $vrspec vrname vrnot vrisbool] |
| 1400 |
if {![info exists vrname_map($vrname)]} { |
| 1401 |
set maplist [list $vrname [sgr hi $vrname]] |
| 1402 |
# also highlight shortcut if any |
| 1403 |
if {[info exists ::g_variantShortcut($vrname)]} { |
| 1404 |
lappend maplist $::g_variantShortcut($vrname) [sgr hi\ |
| 1405 |
$::g_variantShortcut($vrname)] |
| 1406 |
} |
| 1407 |
set vrname_map($vrname) $maplist |
| 1408 |
} |
| 1409 |
# adapt variant value to highlight if boolean |
| 1410 |
set maplist {} |
| 1411 |
foreach vrvalue $vrvalues { |
| 1412 |
if {$vrisbool} { |
| 1413 |
set vrshort [expr {$vrvalue ? {+} : {-}}]$vrname |
| 1414 |
lappend maplist $vrshort [sgr hi $vrshort] |
| 1415 |
set vrvalue [expr {$vrvalue ? {on} : {off}}] |
| 1416 |
} |
| 1417 |
lappend maplist $vrvalue [sgr hi $vrvalue] |
| 1418 |
} |
| 1419 |
lappend vrval_map($vrname) {*}$maplist |
| 1420 |
} |
| 1421 |
} |
| 1422 |
} |
| 1423 |
return [list [array get vrname_map] [array get vrval_map]] |
| 1424 |
} |
| 1425 |
|
| 1426 |
# Format list of modules obtained from a getModules call in upper context |
| 1427 |
proc reportModules {search_queries header hsgrkey hstyle show_mtime show_idx\ |
| 1428 |
one_per_line theader_cols excluded_tag {mod_list_order {}}} { |
| 1429 |
# link to the result module list obtained in caller context |
| 1430 |
upvar mod_list mod_list |
| 1431 |
|
| 1432 |
# output is JSON format |
| 1433 |
set json [isStateEqual report_format json] |
| 1434 |
|
| 1435 |
# is some module variant specified in search query |
| 1436 |
set variant_spec_in_query 0 |
| 1437 |
foreach modspec $search_queries { |
| 1438 |
if {[llength [getVariantListFromVersSpec $modspec]]} { |
| 1439 |
set variant_spec_in_query 1 |
| 1440 |
break |
| 1441 |
} |
| 1442 |
} |
| 1443 |
|
| 1444 |
# elements to include in output |
| 1445 |
if {[set report_indesym [isEltInReport indesym 0]]} { |
| 1446 |
set report_sym 0 |
| 1447 |
} else { |
| 1448 |
set report_sym [isEltInReport sym] |
| 1449 |
} |
| 1450 |
set report_tag [isEltInReport tag] |
| 1451 |
set report_alias [expr {[isEltInReport alias] || [isEltInReport\ |
| 1452 |
provided-alias]}] |
| 1453 |
# enable variant report if variantifspec configured and some variant is |
| 1454 |
# specified in query or variant configured for report or list sub-command |
| 1455 |
# json output |
| 1456 |
set report_variant [expr {($variant_spec_in_query && [isEltInReport\ |
| 1457 |
variantifspec 0]) || [isEltInReport variant [expr {[currentState\ |
| 1458 |
commandname] eq {list} && $json}]]}] |
| 1459 |
set collect_variant_from [expr {[currentState commandname] in {avail\ |
| 1460 |
spider} ? {2} : {0}}] |
| 1461 |
|
| 1462 |
# prepare list of tag abbreviations that can be substituted and list of |
| 1463 |
# tags whose name should be colored |
| 1464 |
getConf tag_abbrev |
| 1465 |
getConf tag_color_name |
| 1466 |
|
| 1467 |
# prepare results for display |
| 1468 |
set alias_colored [isSgrkeyColored al] |
| 1469 |
set default_colored [isSgrkeyColored de] |
| 1470 |
set himatchmap [prepareMapToHightlightSubstr {*}$search_queries] |
| 1471 |
lassign [prepareMapToHightlightVariant {*}$search_queries]\ |
| 1472 |
himatcharrvrmap himatcharrvrvalmap |
| 1473 |
set clean_list {} |
| 1474 |
set vr_list {} |
| 1475 |
set via [expr {[isEltInReport via] ? [getViaModuleForModulepath $header] :\ |
| 1476 |
{}}] |
| 1477 |
|
| 1478 |
# treat elements in specified order if any |
| 1479 |
##nagelfar ignore #2 Badly formed if statement |
| 1480 |
foreach elt [if {![llength $mod_list_order]} {array names mod_list}\ |
| 1481 |
{set mod_list_order}] { |
| 1482 |
if {$report_variant} { |
| 1483 |
set vr_list [getVariantList $elt [expr {$json ? 4 : 7}] 0\ |
| 1484 |
$collect_variant_from] |
| 1485 |
} |
| 1486 |
set sym_list [getVersAliasList $elt] |
| 1487 |
# fetch tags but clear excluded tag |
| 1488 |
set tag_list [replaceFromList [getTagList $elt [lindex $mod_list($elt)\ |
| 1489 |
2]] $excluded_tag] |
| 1490 |
# abbreviate tags unless for json output |
| 1491 |
if {!$json} { |
| 1492 |
set tag_list [abbrevTagList $tag_list] |
| 1493 |
} |
| 1494 |
set dispsgr {} |
| 1495 |
# ignore "version" entries as symbolic version are treated |
| 1496 |
# along to their relative modulefile not independently |
| 1497 |
switch -- [lindex $mod_list($elt) 0] { |
| 1498 |
directory { |
| 1499 |
if {$json} { |
| 1500 |
##nagelfar ignore +2 Found constant |
| 1501 |
set dispsgr [formatListEltToJsonDisplay $elt type s directory\ |
| 1502 |
1 symbols a $sym_list 1 via s $via 1] |
| 1503 |
} elseif {$show_mtime} { |
| 1504 |
# append / char after name to clearly indicate this is a dir |
| 1505 |
lassign [formatListEltToLongDisplay $elt di / $sym_list sy {}\ |
| 1506 |
$default_colored $himatchmap] disp dispsgr displen |
| 1507 |
} else { |
| 1508 |
lassign [formatListEltToDisplay $elt di / $sym_list sy\ |
| 1509 |
$report_sym $default_colored {} 0 {} {} 0 $himatchmap] disp\ |
| 1510 |
dispsgr displen |
| 1511 |
} |
| 1512 |
} |
| 1513 |
modulefile - virtual { |
| 1514 |
if {$json} { |
| 1515 |
##nagelfar ignore +4 Found constant |
| 1516 |
set dispsgr [formatListEltToJsonDisplay $elt type s modulefile\ |
| 1517 |
1 variants o $vr_list $report_variant symbols a $sym_list 1\ |
| 1518 |
tags a $tag_list 1 pathname s [lindex $mod_list($elt) 2] 1\ |
| 1519 |
via s $via 1] |
| 1520 |
} elseif {$show_mtime} { |
| 1521 |
set clock_mtime [expr {[lindex $mod_list($elt) 1] ne {} ?\ |
| 1522 |
[clock format [lindex $mod_list($elt) 1] -format {%Y/%m/%d\ |
| 1523 |
%H:%M:%S}] : {}}] |
| 1524 |
# add to display file modification time in addition |
| 1525 |
# to potential syms |
| 1526 |
lassign [formatListEltToLongDisplay $elt {} {} $sym_list sy\ |
| 1527 |
$clock_mtime $default_colored $himatchmap] disp dispsgr\ |
| 1528 |
displen |
| 1529 |
} else { |
| 1530 |
lassign [formatListEltToDisplay $elt {} {} $sym_list sy\ |
| 1531 |
$report_sym $default_colored $tag_list $report_tag $vr_list\ |
| 1532 |
va $report_variant $himatchmap $himatcharrvrmap\ |
| 1533 |
$himatcharrvrvalmap] disp dispsgr displen |
| 1534 |
} |
| 1535 |
} |
| 1536 |
alias { |
| 1537 |
if {$json} { |
| 1538 |
##nagelfar ignore +3 Found constant |
| 1539 |
set dispsgr [formatListEltToJsonDisplay $elt type s alias 1\ |
| 1540 |
symbols a $sym_list 1 tags a $tag_list 1 target s [lindex\ |
| 1541 |
$mod_list($elt) 1] 1 via s $via 1] |
| 1542 |
} elseif {$show_mtime} { |
| 1543 |
lassign [formatListEltToLongDisplay $elt al " -> [lindex\ |
| 1544 |
$mod_list($elt) 1]" $sym_list sy {} $default_colored\ |
| 1545 |
$himatchmap] disp dispsgr displen |
| 1546 |
} elseif {$report_alias} { |
| 1547 |
# add a '@' sym to indicate elt is an alias if not colored |
| 1548 |
if {!$alias_colored} { |
| 1549 |
lappend sym_list @ |
| 1550 |
# track use of '@' sym to add it to the output key |
| 1551 |
if {$report_sym && ![info exists ::g_used_alias_nocolor]} { |
| 1552 |
set ::g_used_alias_nocolor 1 |
| 1553 |
} |
| 1554 |
} |
| 1555 |
lassign [formatListEltToDisplay $elt al {} $sym_list sy\ |
| 1556 |
$report_sym $default_colored $tag_list $report_tag {} {} 0\ |
| 1557 |
$himatchmap] disp dispsgr displen |
| 1558 |
} |
| 1559 |
} |
| 1560 |
version { |
| 1561 |
# report symbolic version independently from the module it is |
| 1562 |
# attached to. only done on regular or terse output when 'indesym' |
| 1563 |
# element is in relative output configuration option |
| 1564 |
if {$report_indesym} { |
| 1565 |
lassign [formatListEltToDisplay $elt sy {} {} {} 0 0 {} 0 {}\ |
| 1566 |
{} 0 $himatchmap] disp dispsgr displen |
| 1567 |
} |
| 1568 |
} |
| 1569 |
} |
| 1570 |
if {$dispsgr ne {}} { |
| 1571 |
if {$json} { |
| 1572 |
lappend clean_list $dispsgr |
| 1573 |
} else { |
| 1574 |
lappend clean_list $disp |
| 1575 |
set sgrmap($disp) $dispsgr |
| 1576 |
set lenmap($disp) $displen |
| 1577 |
} |
| 1578 |
} |
| 1579 |
} |
| 1580 |
|
| 1581 |
set len_list {} |
| 1582 |
set max_len 0 |
| 1583 |
# dictionary-sort results unless if output order is specified |
| 1584 |
if {![llength $mod_list_order]} { |
| 1585 |
set clean_list [lsort -dictionary $clean_list] |
| 1586 |
} |
| 1587 |
if {$json} { |
| 1588 |
##nagelfar ignore Found constant |
| 1589 |
upvar 0 clean_list display_list |
| 1590 |
if {![info exists display_list]} { |
| 1591 |
set display_list {} |
| 1592 |
} |
| 1593 |
} else { |
| 1594 |
set display_list {} |
| 1595 |
foreach disp $clean_list { |
| 1596 |
# compute display element length list on sorted result |
| 1597 |
lappend display_list $sgrmap($disp) |
| 1598 |
lappend len_list $lenmap($disp) |
| 1599 |
if {$lenmap($disp) > $max_len} { |
| 1600 |
set max_len $lenmap($disp) |
| 1601 |
} |
| 1602 |
} |
| 1603 |
} |
| 1604 |
|
| 1605 |
# output table header if needed and not yet done |
| 1606 |
if {[llength $display_list] && $show_mtime && ![isStateDefined\ |
| 1607 |
theader_shown]} { |
| 1608 |
setState theader_shown 1 |
| 1609 |
displayTableHeader {*}$theader_cols |
| 1610 |
} |
| 1611 |
|
| 1612 |
# output formatted elements |
| 1613 |
displayElementList $header $hsgrkey $hstyle $one_per_line $show_idx 1\ |
| 1614 |
$display_list $len_list $max_len $via |
| 1615 |
} |
| 1616 |
|
| 1617 |
proc showModulePath {} { |
| 1618 |
set modpathlist [getModulePathList] |
| 1619 |
if {[llength $modpathlist]} { |
| 1620 |
report {Search path for module files (in search order):} |
| 1621 |
foreach path $modpathlist { |
| 1622 |
report " [sgr mp $path]" |
| 1623 |
} |
| 1624 |
} else { |
| 1625 |
reportWarning {No directories on module search path} |
| 1626 |
} |
| 1627 |
} |
| 1628 |
|
| 1629 |
proc displayTableHeader {sgrkey args} { |
| 1630 |
foreach {title col_len} $args { |
| 1631 |
set col "- [sgr $sgrkey $title] " |
| 1632 |
append col [string repeat - [expr {$col_len - [string length $title] -\ |
| 1633 |
3}]] |
| 1634 |
lappend col_list $col |
| 1635 |
} |
| 1636 |
|
| 1637 |
report [join $col_list .] |
| 1638 |
} |
| 1639 |
|
| 1640 |
proc displaySeparatorLine {{title {}} {sgrkey {}} {extra {}}} { |
| 1641 |
set tty_cols [getState term_columns] |
| 1642 |
if {$title eq {}} { |
| 1643 |
# adapt length if screen width is very small |
| 1644 |
set max_rep 67 |
| 1645 |
set rep [expr {$tty_cols > $max_rep ? $max_rep : $tty_cols}] |
| 1646 |
report [string repeat - $rep] |
| 1647 |
} else { |
| 1648 |
set len [string length $title$extra] |
| 1649 |
set lrep [tcl::mathfunc::max [expr {($tty_cols - $len - 2)/2}] 1] |
| 1650 |
set rrep [tcl::mathfunc::max [expr {$tty_cols - $len - 2 - $lrep}] 1] |
| 1651 |
report "[string repeat - $lrep] [sgr $sgrkey $title]$extra [string\ |
| 1652 |
repeat - $rrep]" |
| 1653 |
} |
| 1654 |
} |
| 1655 |
|
| 1656 |
# get a list of elements and print them in a column or in a |
| 1657 |
# one-per-line fashion |
| 1658 |
proc displayElementList {header sgrkey hstyle one_per_line display_idx\ |
| 1659 |
start_idx display_list {len_list {}} {max_len 0} {via {}}} { |
| 1660 |
set elt_cnt [llength $display_list] |
| 1661 |
reportDebug "header=$header, sgrkey=$sgrkey, hstyle=$hstyle,\ |
| 1662 |
elt_cnt=$elt_cnt, max_len=$max_len, one_per_line=$one_per_line,\ |
| 1663 |
display_idx=$display_idx, start_idx=$start_idx, via=$via" |
| 1664 |
|
| 1665 |
# end proc if no element are to print |
| 1666 |
if {$elt_cnt == 0} { |
| 1667 |
return |
| 1668 |
} |
| 1669 |
# output is JSON format |
| 1670 |
set json [isStateEqual report_format json] |
| 1671 |
|
| 1672 |
# display header if any provided |
| 1673 |
if {$header ne {noheader}} { |
| 1674 |
set header [getModulepathLabel $header] |
| 1675 |
if {$json} { |
| 1676 |
report "\"$header\": \{" |
| 1677 |
} elseif {$hstyle eq {sepline}} { |
| 1678 |
set extra [expr {[string length $via] ? " (via $via)" : {}}] |
| 1679 |
displaySeparatorLine $header $sgrkey $extra |
| 1680 |
} else { |
| 1681 |
report [sgr $sgrkey $header]: |
| 1682 |
} |
| 1683 |
} |
| 1684 |
|
| 1685 |
# increase index length when 100+ modules to report |
| 1686 |
if {$display_idx} { |
| 1687 |
set idx_len [expr {$elt_cnt > 99 ? {3} : {2}}] |
| 1688 |
} |
| 1689 |
|
| 1690 |
if {$json} { |
| 1691 |
set displist [join $display_list ,\n] |
| 1692 |
# display one element per line |
| 1693 |
} elseif {$one_per_line} { |
| 1694 |
if {$display_idx} { |
| 1695 |
set idx $start_idx |
| 1696 |
foreach elt $display_list { |
| 1697 |
append displist [format "%${idx_len}d) %s " $idx $elt] \n |
| 1698 |
incr idx |
| 1699 |
} |
| 1700 |
} else { |
| 1701 |
append displist [join $display_list \n] \n |
| 1702 |
} |
| 1703 |
# elsewhere display elements in columns |
| 1704 |
} else { |
| 1705 |
# save room for numbers and spacing: 2 or 3 digits + ) + space |
| 1706 |
set elt_prefix_len [expr {$display_idx ? $idx_len + 2 : {0}}] |
| 1707 |
# save room for two spaces after element |
| 1708 |
set elt_suffix_len 2 |
| 1709 |
|
| 1710 |
# compute rows*cols grid size with optimized column number |
| 1711 |
# the size of each column is computed to display as much column |
| 1712 |
# as possible on each line |
| 1713 |
incr max_len $elt_suffix_len |
| 1714 |
foreach len $len_list { |
| 1715 |
lappend elt_len [incr len $elt_suffix_len] |
| 1716 |
} |
| 1717 |
|
| 1718 |
set tty_cols [getState term_columns] |
| 1719 |
# find valid grid by starting with non-optimized solution where each |
| 1720 |
# column length is equal to the length of the biggest element to display |
| 1721 |
set cur_cols [tcl::mathfunc::max [expr {int(($tty_cols - \ |
| 1722 |
$elt_prefix_len) / $max_len)}] 0] |
| 1723 |
# when display is found too short to display even one column |
| 1724 |
if {$cur_cols == 0} { |
| 1725 |
set cols 1 |
| 1726 |
set rows $elt_cnt |
| 1727 |
array set col_width [list 0 $max_len] |
| 1728 |
} else { |
| 1729 |
set cols 0 |
| 1730 |
set rows 0 |
| 1731 |
} |
| 1732 |
set last_round 0 |
| 1733 |
set restart_loop 0 |
| 1734 |
while {$cur_cols > $cols} { |
| 1735 |
if {!$restart_loop} { |
| 1736 |
if {$last_round} { |
| 1737 |
incr cur_rows |
| 1738 |
} else { |
| 1739 |
set cur_rows [expr {int(ceil(double($elt_cnt) / $cur_cols))}] |
| 1740 |
} |
| 1741 |
for {set i 0} {$i < $cur_cols} {incr i} { |
| 1742 |
set cur_col_width($i) 0 |
| 1743 |
} |
| 1744 |
for {set i 0} {$i < $cur_rows} {incr i} { |
| 1745 |
set row_width($i) 0 |
| 1746 |
} |
| 1747 |
set istart 0 |
| 1748 |
} else { |
| 1749 |
##nagelfar ignore Unknown variable |
| 1750 |
set istart [expr {$col * $cur_rows}] |
| 1751 |
# only remove width of elements from current col |
| 1752 |
for {set row 0} {$row < ($i % $cur_rows)} {incr row} { |
| 1753 |
##nagelfar ignore Unknown variable |
| 1754 |
incr row_width($row) -[expr {$pre_col_width + $elt_prefix_len}] |
| 1755 |
} |
| 1756 |
} |
| 1757 |
set restart_loop 0 |
| 1758 |
for {set i $istart} {$i < $elt_cnt} {incr i} { |
| 1759 |
set col [expr {int($i / $cur_rows)}] |
| 1760 |
set row [expr {$i % $cur_rows}] |
| 1761 |
# restart loop if a column width change |
| 1762 |
if {[lindex $elt_len $i] > $cur_col_width($col)} { |
| 1763 |
set pre_col_width $cur_col_width($col) |
| 1764 |
set cur_col_width($col) [lindex $elt_len $i] |
| 1765 |
set restart_loop 1 |
| 1766 |
break |
| 1767 |
} |
| 1768 |
# end search of maximum number of columns if computed row width |
| 1769 |
# is larger than terminal width |
| 1770 |
if {[incr row_width($row) +[expr {$cur_col_width($col) \ |
| 1771 |
+ $elt_prefix_len}]] > $tty_cols} { |
| 1772 |
# start last optimization pass by increasing row number until |
| 1773 |
# reaching number used for previous column number, by doing so |
| 1774 |
# this number of column may pass in terminal width, if not |
| 1775 |
# fallback to previous number of column |
| 1776 |
if {$last_round && $cur_rows == $rows} { |
| 1777 |
incr cur_cols -1 |
| 1778 |
} else { |
| 1779 |
set last_round 1 |
| 1780 |
} |
| 1781 |
break |
| 1782 |
} |
| 1783 |
} |
| 1784 |
# went through all elements without reaching terminal width limit so |
| 1785 |
# this number of column solution is valid, try next with a greater |
| 1786 |
# column number |
| 1787 |
if {$i == $elt_cnt} { |
| 1788 |
set cols $cur_cols |
| 1789 |
set rows $cur_rows |
| 1790 |
array set col_width [array get cur_col_width] |
| 1791 |
# number of column is fixed if last optimization round has started |
| 1792 |
# reach end also if there is only one row of results |
| 1793 |
if {!$last_round && $rows > 1} { |
| 1794 |
incr cur_cols |
| 1795 |
} |
| 1796 |
} |
| 1797 |
|
| 1798 |
} |
| 1799 |
reportDebug list=$display_list |
| 1800 |
reportDebug "rows/cols=$rows/$cols,\ |
| 1801 |
lastcol_item_cnt=[expr {int($elt_cnt % $rows)}]" |
| 1802 |
|
| 1803 |
for {set row 0} {$row < $rows} {incr row} { |
| 1804 |
for {set col 0} {$col < $cols} {incr col} { |
| 1805 |
set index [expr {$col * $rows + $row}] |
| 1806 |
if {$index < $elt_cnt} { |
| 1807 |
if {$display_idx} { |
| 1808 |
append displist [format "%${idx_len}d) " [expr {$index +\ |
| 1809 |
$start_idx}]] |
| 1810 |
} |
| 1811 |
# cannot use 'format' as strings may contain SGR codes |
| 1812 |
append displist [lindex $display_list $index][string repeat\ |
| 1813 |
{ } [expr {$col_width($col) - [lindex $len_list $index]}]] |
| 1814 |
} |
| 1815 |
} |
| 1816 |
append displist \n |
| 1817 |
} |
| 1818 |
} |
| 1819 |
if {$json && $header ne {noheader}} { |
| 1820 |
append displist "\n\}" |
| 1821 |
} |
| 1822 |
report $displist 1 |
| 1823 |
reportSeparateNextContent |
| 1824 |
} |
| 1825 |
|
| 1826 |
# Report an output key to help understand what the SGR used on this output |
| 1827 |
# correspond to |
| 1828 |
proc displayKey {} { |
| 1829 |
# specific key entry for symbolic version if reported independently |
| 1830 |
set typesym [list {symbolic-version}] |
| 1831 |
if {![isEltInReport indesym 0]} { |
| 1832 |
lappend typesym [sgr se (]<SGR>[sgr se )] 18 |
| 1833 |
} |
| 1834 |
|
| 1835 |
array set skipsgr [list hi 1 db 1 tr 1 se 1 er 1 wa 1 me 1 in 1 cm 1 va 1] |
| 1836 |
array set typesgr [list mp modulepath di [list directory <SGR>/ 10] al\ |
| 1837 |
module-alias sy $typesym de [list {default-version}]] |
| 1838 |
|
| 1839 |
set display_list {} |
| 1840 |
set len_list {} |
| 1841 |
foreach key [array names ::g_used_colors] { |
| 1842 |
# sgr key matches a basic modulefile type |
| 1843 |
if {[info exists typesgr($key)]} { |
| 1844 |
# the way to describe key is already defined |
| 1845 |
if {[llength $typesgr($key)] > 1} { |
| 1846 |
lassign $typesgr($key) desc desctmp len |
| 1847 |
set desc [string map [list <SGR> [sgr $key $desc]] $desctmp] |
| 1848 |
} else { |
| 1849 |
set desc [lindex $typesgr($key) 0] |
| 1850 |
} |
| 1851 |
if {$key eq {sy} && [info exists ::g_used_sym_nocolor]} { |
| 1852 |
unset ::g_used_sym_nocolor |
| 1853 |
} |
| 1854 |
# key is a tag abbreviation |
| 1855 |
} elseif {[info exists ::g_abbrevTag($key)]} { |
| 1856 |
set desc $::g_abbrevTag($key) |
| 1857 |
# if not part of the ignored list, this key corresponds to a tag name |
| 1858 |
} elseif {![info exists skipsgr($key)]} { |
| 1859 |
set desc $key |
| 1860 |
} |
| 1861 |
if {[info exists desc]} { |
| 1862 |
# define key description |
| 1863 |
if {![info exists len]} { |
| 1864 |
set len [string length $desc] |
| 1865 |
set desc [sgr $key $desc] |
| 1866 |
} |
| 1867 |
lappend display_list $desc |
| 1868 |
lappend len_list $len |
| 1869 |
unset desc |
| 1870 |
unset len |
| 1871 |
} |
| 1872 |
} |
| 1873 |
|
| 1874 |
# include var=val key if any other variant form is present in report |
| 1875 |
if {![info exists ::g_used_va(val)] && [array exists ::g_used_va]} { |
| 1876 |
set ::g_used_va(val) 1 |
| 1877 |
} |
| 1878 |
# add key for variant reports |
| 1879 |
if {[info exists ::g_used_va(on)]} { |
| 1880 |
lappend display_list "[sgr se \{][sgr va +variant][sgr se\ |
| 1881 |
\}]=[sgr se \{][sgr va variant=on][sgr se \}]" |
| 1882 |
lappend len_list 23 |
| 1883 |
} |
| 1884 |
if {[info exists ::g_used_va(off)]} { |
| 1885 |
lappend display_list "[sgr se \{][sgr va -variant][sgr se\ |
| 1886 |
\}]=[sgr se \{][sgr va variant=off][sgr se \}]" |
| 1887 |
lappend len_list 24 |
| 1888 |
} |
| 1889 |
foreach sc [array names ::g_used_va] { |
| 1890 |
if {$sc ni {on off val}} { |
| 1891 |
lappend display_list "[sgr se \{][sgr va ${sc}value][sgr se\ |
| 1892 |
\}]=[sgr se \{][sgr va $::g_used_va($sc)=value][sgr se \}]" |
| 1893 |
lappend len_list [expr {17 + [string length $::g_used_va($sc)]}] |
| 1894 |
} |
| 1895 |
} |
| 1896 |
# finish with variant=value entry as it is referred by other variant keys |
| 1897 |
if {[info exists ::g_used_va(val)]} { |
| 1898 |
lappend display_list "[sgr se \{][sgr va variant=value][sgr se \}]" |
| 1899 |
lappend len_list 15 |
| 1900 |
} |
| 1901 |
|
| 1902 |
# add key for alias if '@' put in parentheses |
| 1903 |
if {[info exists ::g_used_alias_nocolor]} { |
| 1904 |
lappend display_list "[sgr se (]@[sgr se )]=module-alias" |
| 1905 |
lappend len_list 9 |
| 1906 |
} |
| 1907 |
# add key for symbolic version if any put in parentheses but no color |
| 1908 |
if {[info exists ::g_used_sym_nocolor]} { |
| 1909 |
lappend display_list "[sgr se (]symbolic-version[sgr se )]" |
| 1910 |
lappend len_list 18 |
| 1911 |
} |
| 1912 |
|
| 1913 |
# add key for module tag if any put in angle brackets |
| 1914 |
if {[array exists ::g_used_tags]} { |
| 1915 |
lappend display_list "[sgr se <]module-tag[sgr se >]" |
| 1916 |
lappend len_list 12 |
| 1917 |
} |
| 1918 |
# report translation of each uncolored tag abbreviation that have been used |
| 1919 |
foreach tag [array names ::g_used_tags] { |
| 1920 |
if {![info exists ::g_used_colors($tag)] && [info exists\ |
| 1921 |
::g_abbrevTag($tag)]} { |
| 1922 |
lappend display_list [sgr se <]$tag[sgr se >]=$::g_abbrevTag($tag) |
| 1923 |
lappend len_list [expr {[string length $tag] + [string length\ |
| 1924 |
$::g_abbrevTag($tag)] + 3}] |
| 1925 |
} |
| 1926 |
} |
| 1927 |
|
| 1928 |
# find largest element |
| 1929 |
set max_len 0 |
| 1930 |
foreach len $len_list { |
| 1931 |
if {$len > $max_len} { |
| 1932 |
set max_len $len |
| 1933 |
} |
| 1934 |
} |
| 1935 |
|
| 1936 |
if {[llength $display_list]} { |
| 1937 |
# display header |
| 1938 |
report Key: |
| 1939 |
# display key content |
| 1940 |
displayElementList noheader {} {} 0 0 0 $display_list $len_list $max_len |
| 1941 |
} |
| 1942 |
} |
| 1943 |
|
| 1944 |
# Return conf value and from where an eventual def value has been overridden |
| 1945 |
proc displayConfig {val env_var {asked 0} {trans {}} {locked 0}} { |
| 1946 |
array set transarr $trans |
| 1947 |
|
| 1948 |
# get overridden value and know what has overridden it |
| 1949 |
if {$asked} { |
| 1950 |
set defby " (cmd-line)" |
| 1951 |
} elseif {$env_var ne {} && !$locked && [isEnvVarDefined $env_var]} { |
| 1952 |
set defby " (env-var)" |
| 1953 |
} elseif {$locked} { |
| 1954 |
set defby " (locked)" |
| 1955 |
} else { |
| 1956 |
set defby {} |
| 1957 |
} |
| 1958 |
|
| 1959 |
# translate fetched value if translation table exists |
| 1960 |
if {[info exists transarr($val)]} { |
| 1961 |
set val $transarr($val) |
| 1962 |
} |
| 1963 |
|
| 1964 |
return $val$defby |
| 1965 |
} |
| 1966 |
|
| 1967 |
# report linter output as error/warning messages |
| 1968 |
proc displayLinterOutput {linter output} { |
| 1969 |
switch -- $linter { |
| 1970 |
nagelfar { |
| 1971 |
# parsing linter output |
| 1972 |
set report_list {} |
| 1973 |
foreach line [split $output \n] { |
| 1974 |
set firstword [string range $line 0 [string first { } $line]-1] |
| 1975 |
switch -- $firstword { |
| 1976 |
Checking - Parsing {} |
| 1977 |
Line { |
| 1978 |
# add message of previous line if any |
| 1979 |
if {[info exists msg]} { |
| 1980 |
lappend report_list $msg |
| 1981 |
} |
| 1982 |
|
| 1983 |
# extract information from message line |
| 1984 |
set colidx [string first : $line] |
| 1985 |
set linenum [string trimleft [string range $line 5\ |
| 1986 |
$colidx-1]] |
| 1987 |
set severity [string index $line $colidx+2] |
| 1988 |
switch -- $severity { |
| 1989 |
W { |
| 1990 |
set severity WARNING |
| 1991 |
set sgrkey wa |
| 1992 |
set raisecnt 0 |
| 1993 |
} |
| 1994 |
E { |
| 1995 |
set severity ERROR |
| 1996 |
set sgrkey er |
| 1997 |
set raisecnt 1 |
| 1998 |
} |
| 1999 |
default { |
| 2000 |
set severity NOTICE |
| 2001 |
set sgrkey in |
| 2002 |
set raisecnt 0 |
| 2003 |
} |
| 2004 |
} |
| 2005 |
set msg [string range $line $colidx+4 end] |
| 2006 |
|
| 2007 |
# start recorded message properties |
| 2008 |
lappend report_list $linenum $severity $sgrkey $raisecnt |
| 2009 |
} |
| 2010 |
default { |
| 2011 |
# this line is continuing message started previously |
| 2012 |
append msg \n[string trimleft $line] |
| 2013 |
} |
| 2014 |
} |
| 2015 |
} |
| 2016 |
# add message of last line if any |
| 2017 |
if {[info exists msg]} { |
| 2018 |
lappend report_list $msg |
| 2019 |
unset msg |
| 2020 |
} |
| 2021 |
|
| 2022 |
# report messages |
| 2023 |
foreach {linenum severity sgrkey raisecnt mesg} $report_list { |
| 2024 |
reportError $mesg "[format %-7s $severity] line $linenum"\ |
| 2025 |
$sgrkey $raisecnt |
| 2026 |
} |
| 2027 |
} |
| 2028 |
default { |
| 2029 |
reportError $output |
| 2030 |
} |
| 2031 |
} |
| 2032 |
} |
| 2033 |
|
| 2034 |
proc reportMlUsage {} { |
| 2035 |
reportVersion |
| 2036 |
report {Usage: ml [options] [command] [args ...] |
| 2037 |
ml [options] [[-]modulefile ...] |
| 2038 |
|
| 2039 |
Examples: |
| 2040 |
ml equivalent to: module list |
| 2041 |
ml foo bar equivalent to: module load foo bar |
| 2042 |
ml -foo -bar baz equivalent to: module unload foo bar; module load baz |
| 2043 |
ml avail -t equivalent to: module avail -t |
| 2044 |
|
| 2045 |
See 'module --help' to get available commands and options.} |
| 2046 |
} |
| 2047 |
|
| 2048 |
proc reportUsage {} { |
| 2049 |
reportVersion |
| 2050 |
##nagelfar ignore #111 Too long line |
| 2051 |
report {Usage: module [options] [command] [args ...] |
| 2052 |
|
| 2053 |
Loading / Unloading commands: |
| 2054 |
add | load modulefile [...] Load modulefile(s) |
| 2055 |
try-add | try-load modfile [...] Load modfile(s), no complain if not found |
| 2056 |
add-any | load-any modfile [...] Load first available modulefile in list |
| 2057 |
rm | unload modulefile [...] Remove modulefile(s) |
| 2058 |
purge Unload all loaded modulefiles |
| 2059 |
reload | update Unload then load all loaded modulefiles |
| 2060 |
switch | swap [mod1] mod2 Unload mod1 and load mod2 |
| 2061 |
refresh Refresh loaded module volatile components |
| 2062 |
reset Restore initial environment |
| 2063 |
|
| 2064 |
Listing / Searching commands: |
| 2065 |
list [-a] [-t|-l|-j] [-S|-C] [mod ...] |
| 2066 |
List all or matching loaded modules |
| 2067 |
avail [-a] [-t|-l|-j] [-S|-C] [-d|-L] [--indepth|--no-indepth] [mod ...] |
| 2068 |
List all or matching available modules |
| 2069 |
aliases [-a] List all module aliases |
| 2070 |
whatis [-a] [-j] [modulefile ...] Print whatis information of modulefile(s) |
| 2071 |
apropos | keyword | search [-a] [-j] str |
| 2072 |
Search all name and whatis containing str |
| 2073 |
spider [-a] [-t|-l|-j] [-S|-C] [-d|-L] [--indepth|--no-indepth] [mod ...] |
| 2074 |
Scan all modulepaths and list all or |
| 2075 |
matching available modules |
| 2076 |
is-loaded [modulefile ...] Test if any of the modulefile(s) are loaded |
| 2077 |
is-avail modulefile [...] Is any of the modulefile(s) available |
| 2078 |
info-loaded modulefile Get full name of matching loaded module(s) |
| 2079 |
|
| 2080 |
Collection of modules handling commands: |
| 2081 |
save [collection|file] Save current module list to collection |
| 2082 |
restore [collection|file] Restore module list from collection or file |
| 2083 |
saverm | disable [collection] Remove saved collection |
| 2084 |
saveshow | describe [coll|file] Display information about collection |
| 2085 |
savelist [-a] [-t|-l|-j] [-S|-C] [collection ...] |
| 2086 |
List all or matching saved collections |
| 2087 |
is-saved [collection ...] Test if any of the collection(s) exists |
| 2088 |
stash Save current environment and reset |
| 2089 |
stashpop [stash] Restore then remove stash collection |
| 2090 |
stashrm [stash] Remove stash collection |
| 2091 |
stashshow [stash] Display information about stash collection |
| 2092 |
stashclear Remove all stash collections |
| 2093 |
stashlist List all stash collections |
| 2094 |
|
| 2095 |
Environment direct handling commands: |
| 2096 |
prepend-path [-d c] var val [...] Prepend value to environment variable |
| 2097 |
append-path [-d c] var val [...] Append value to environment variable |
| 2098 |
remove-path [-d c] var val [...] Remove value from environment variable |
| 2099 |
|
| 2100 |
Module cache handling commands: |
| 2101 |
cachebuild [modulepath ...] Create cache file for modulepath(s) |
| 2102 |
cacheclear Delete cache file in enabled modulepath(s) |
| 2103 |
|
| 2104 |
Other commands: |
| 2105 |
help [modulefile ...] Print this or modulefile(s) help info |
| 2106 |
display | show modulefile [...] Display information about modulefile(s) |
| 2107 |
test [modulefile ...] Test modulefile(s) |
| 2108 |
use [-a|-p] dir [...] Add dir(s) to MODULEPATH variable |
| 2109 |
unuse dir [...] Remove dir(s) from MODULEPATH variable |
| 2110 |
is-used [dir ...] Is any of the dir(s) enabled in MODULEPATH |
| 2111 |
path modulefile Print modulefile path |
| 2112 |
paths modulefile Print path of matching available modules |
| 2113 |
clear [-f] Reset Modules-specific runtime information |
| 2114 |
source scriptfile [...] Execute scriptfile(s) |
| 2115 |
config [--dump-state|name [val]] Display or set Modules configuration |
| 2116 |
state [name] Display Modules state |
| 2117 |
sh-to-mod shell shellscript [arg ...] |
| 2118 |
Make modulefile from script env changes |
| 2119 |
mod-to-sh shell modulefile [...] |
| 2120 |
Make shell code from modulefile env changes |
| 2121 |
edit modulefile Open modulefile in editor |
| 2122 |
lint [-a] [modulefile ...] Check syntax of modulefile |
| 2123 |
|
| 2124 |
Switches: |
| 2125 |
-t | --terse Display output in terse format |
| 2126 |
-l | --long Display output in long format |
| 2127 |
-j | --json Display output in JSON format |
| 2128 |
-o LIST | --output=LIST |
| 2129 |
Define elements to output on 'avail', 'spider' or 'list' |
| 2130 |
sub-cmds in addition to module names (LIST is made of items |
| 2131 |
like 'sym', 'tag', 'variant' or 'key' separated by ':') |
| 2132 |
-a | --all Include hidden modules in search |
| 2133 |
-d | --default Only show default versions available |
| 2134 |
-L | --latest Only show latest versions available |
| 2135 |
-S | --starts-with |
| 2136 |
Search modules whose name begins with query string |
| 2137 |
-C | --contains Search modules whose name contains query string |
| 2138 |
-i | --icase Case insensitive match |
| 2139 |
-a | --append Append directory to MODULEPATH (on 'use' sub-command) |
| 2140 |
-p | --prepend Prepend directory to MODULEPATH |
| 2141 |
--auto Enable automated module handling mode |
| 2142 |
--no-auto Disable automated module handling mode |
| 2143 |
-f | --force By-pass dependency consistency, abort on error or |
| 2144 |
confirmation dialog |
| 2145 |
--tag=LIST Apply tag to loading module on 'load', 'try-load', 'load-any' |
| 2146 |
or 'switch' sub-commands (LIST is made of tag names |
| 2147 |
separated by ':') |
| 2148 |
--ignore-cache Ignore module cache |
| 2149 |
--ignore-user-rc |
| 2150 |
Skip evaluation of user-specific module rc file |
| 2151 |
|
| 2152 |
Options: |
| 2153 |
-h | --help This usage info |
| 2154 |
-V | --version Module version |
| 2155 |
--dumpname Module implementation name |
| 2156 |
-D | --debug Enable debug messages |
| 2157 |
-T | --trace Enable trace messages |
| 2158 |
-v | --verbose Enable verbose messages |
| 2159 |
-s | --silent Turn off error, warning and informational messages |
| 2160 |
--timer Report execution times |
| 2161 |
--paginate Pipe mesg output into a pager if stream attached to terminal |
| 2162 |
--no-pager Do not pipe message output into a pager |
| 2163 |
--redirect Send output to stdout (only for sh, bash, ksh, zsh and fish) |
| 2164 |
--no-redirect Send output to stderr |
| 2165 |
--color[=WHEN] Colorize the output; WHEN can be 'always' (default if |
| 2166 |
omitted), 'auto' or 'never' |
| 2167 |
-w COLS | --width=COLS |
| 2168 |
Set output width to COLS columns.} |
| 2169 |
} |
| 2170 |
|
| 2171 |
# create appropriate message and kind of report when a requirement is not |
| 2172 |
# satisfied |
| 2173 |
proc reportMissingPrereqError {curmodnamevr modulepath_list args} { |
| 2174 |
set is_path_specific [llength $modulepath_list] |
| 2175 |
if {[isModuleEvaluated reqlo $curmodnamevr $modulepath_list {*}$args]} { |
| 2176 |
set msg [getErrReqLoMsg $args $is_path_specific] |
| 2177 |
} else { |
| 2178 |
set retiseval [isModuleEvaluated any $curmodnamevr $modulepath_list\ |
| 2179 |
{*}$args] |
| 2180 |
# more appropriate msg if an evaluation was attempted or is by-passed |
| 2181 |
set msg [expr {$retiseval || [getState force] ? [getReqNotLoadedMsg\ |
| 2182 |
$args $is_path_specific] : [getErrPrereqMsg $args 1\ |
| 2183 |
$is_path_specific]}] |
| 2184 |
} |
| 2185 |
|
| 2186 |
knerrorOrWarningIfForced $msg MODULES_ERR_GLOBAL |
| 2187 |
} |
| 2188 |
|
| 2189 |
proc setConflictErrorAsReported {args} { |
| 2190 |
appendNoDupToList ::report_conflict([currentState evalid]) {*}$args |
| 2191 |
# save content added to remove it later if evaluation is withdrawn |
| 2192 |
if {[depthState reportholdid]} { |
| 2193 |
lappend ::g_holdReportConflict([currentState reportholdid]) \ |
| 2194 |
[currentState evalid] $args |
| 2195 |
} |
| 2196 |
} |
| 2197 |
|
| 2198 |
proc isConflictErrorAlreadyReported {msgrecid mod_con_list} { |
| 2199 |
if {[info exists ::report_conflict($msgrecid)]} { |
| 2200 |
return [isIntBetweenList $mod_con_list $::report_conflict($msgrecid)] |
| 2201 |
} else { |
| 2202 |
return 0 |
| 2203 |
} |
| 2204 |
} |
| 2205 |
|
| 2206 |
# Report final error caught on main catch block |
| 2207 |
proc reportFinalError {error_msg} { |
| 2208 |
# render error if not done yet |
| 2209 |
if {$::errorCode ne {MODULES_ERR_RENDERED}} { |
| 2210 |
incrErrorCount |
| 2211 |
renderFalse |
| 2212 |
} |
| 2213 |
|
| 2214 |
if {$::errorCode ni [list MODULES_ERR_RENDERED MODULES_ERR_KNOWN]} { |
| 2215 |
# add web link to report issue unless if an external error is detected |
| 2216 |
set external_error_list [list\ |
| 2217 |
{Can't find a usable init.tcl in the following directories}\ |
| 2218 |
{interpreter uses an incompatible stubs mechanism}\ |
| 2219 |
{dlopen(}\ |
| 2220 |
{couldn't fork child process: resource temporarily unavailable}\ |
| 2221 |
{invalid command name "tcl::mathfunc::max"}] |
| 2222 |
set add_report_link 1 |
| 2223 |
foreach external_error $external_error_list { |
| 2224 |
if {[string equal -length [string length $external_error]\ |
| 2225 |
$external_error $error_msg]} { |
| 2226 |
set add_report_link 0 |
| 2227 |
break |
| 2228 |
} |
| 2229 |
} |
| 2230 |
|
| 2231 |
# report stack trace in addition to the error msg if error is unknown |
| 2232 |
set error_msg $::errorInfo |
| 2233 |
|
| 2234 |
if {$add_report_link} { |
| 2235 |
append error_msg \n[sgr hi {Please report this issue at\ |
| 2236 |
https://github.com/envmodules/modules/issues}] |
| 2237 |
} |
| 2238 |
} |
| 2239 |
|
| 2240 |
reportError $error_msg |
| 2241 |
} |
| 2242 |
|
| 2243 |
# ;;; Local Variables: *** |
| 2244 |
# ;;; mode:tcl *** |
| 2245 |
# ;;; End: *** |
| 2246 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |