forked from envmodules/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodspec.tcl
More file actions
1865 lines (1793 loc) · 64.6 KB
/
Copy pathmodspec.tcl
File metadata and controls
1865 lines (1793 loc) · 64.6 KB
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
##########################################################################
# MODSPEC.TCL, module specification procedures
# Copyright (C) 2016-2026 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/>.
##########################################################################
# Define procedure to get how many parts between passed name and mod are equal
# Adapt procedure code whether icase is enabled or disabled
proc defineModStartNbProc {icase} {
set procname modStartNbProc
if {$icase} {
append procname Icase
}
# define proc if not done yet or if it was defined for another context
if {[info procs modStartNb] eq {} || $::g_modStartNb_proc ne $procname} {
if {[info exists ::g_modStartNb_proc]} {
# remove existing debug trace if any
initProcReportTrace remove modStartNb
rename ::modStartNb ::$::g_modStartNb_proc
}
##nagelfar syntax modStartNb x x
rename ::$procname ::modStartNb
# set report traces if some debug mode enabled
initProcReportTrace add modStartNb
set ::g_modStartNb_proc $procname
}
}
# alternative definitions of modStartNb proc
proc modStartNbProc {mod name} {
# first compare against name's parent chunk by chunk
set modname [getModuleNameFromVersSpec $name]
if {$modname eq {.}} {
set i 0
set imax 0
} else {
set namesplit [split $modname /]
set modsplit [split $mod /]
set imax [tcl::mathfunc::min [llength $namesplit] [llength $modsplit]]
for {set i 0} {$i < $imax} {incr i} {
if {![string equal [lindex $modsplit $i] [lindex $namesplit $i]]} {
break
}
}
}
# if name's parent matches check if full name also matches
if {$i == $imax && [modEq $name $mod eqstart]} {
incr i
}
return $i
}
proc modStartNbProcIcase {mod name} {
set modname [getModuleNameFromVersSpec $name]
if {$modname eq {.}} {
set i 0
set imax 0
} else {
set namesplit [split $modname /]
set modsplit [split $mod /]
##nagelfar ignore #2 Badly formed if statement
set imax [if {[llength $namesplit] < [llength $modsplit]} {llength\
$namesplit} {llength $modsplit}]
for {set i 0} {$i < $imax} {incr i} {
if {![string equal -nocase [lindex $modsplit $i] [lindex $namesplit\
$i]]} {
break
}
}
}
if {$i == $imax && [modEq $name $mod eqstart]} {
incr i
}
return $i
}
# Define procedure to compare module names set as array keys against pattern.
# Adapt procedure code whether implicit_default is enabled or disabled
proc defineGetEqArrayKeyProc {impdfl} {
set procname getEqArrayKeyProc
if {$impdfl} {
append procname Impdfl
}
# define proc if not done yet or if it was defined for another context
if {[info procs getEqArrayKey] eq {} || $::g_getEqArrayKey_proc ne\
$procname} {
if {[info exists ::g_getEqArrayKey_proc]} {
# remove existing debug trace if any
initProcReportTrace remove getEqArrayKey
rename ::getEqArrayKey ::$::g_getEqArrayKey_proc
}
##nagelfar syntax getEqArrayKey x x
rename ::$procname ::getEqArrayKey
# set report traces if some debug mode enabled
initProcReportTrace add getEqArrayKey
set ::g_getEqArrayKey_proc $procname
}
}
# alternative definitions of getEqArrayKey proc
proc getEqArrayKeyProcImpdfl {arrname name} {
set icase [isIcase]
upvar $arrname arr
# extract single module specified if any
lassign [getModuleVersSpec $name] mod modname
# check name eventual icase match
set mod [getArrayKey arr [string trimright $mod /] $icase]
if {$mod ne {} && [info exists arr($mod)]} {
set match $mod
} else {
set mlist {}
foreach elt [array names arr] {
if {[modEq $name $elt]} {
lappend mlist $elt
}
}
if {[llength $mlist] == 1} {
set match [lindex $mlist 0]
# in case multiple modules match query, check directory default and
# return it if it is part of match list, elsewhere return highest result
} elseif {[llength $mlist] > 1} {
# get corresponding icase parent directory
set pname [getArrayKey arr $modname $icase]
if {[info exists arr($pname)]} {
set dfl $pname/[lindex $arr($pname) 1]
}
# resolve symbolic version entries
foreach elt $mlist {
if {[lindex $arr($elt) 0] eq {version}} {
lappend mrlist [lindex $arr($elt) 1]
} else {
lappend mrlist $elt
}
}
if {[info exists dfl] && $dfl in $mrlist} {
set match $dfl
} else {
set match [lindex [lsort -dictionary $mrlist] end]
}
}
}
if {[info exists match]} {
reportDebug "key '$match' in array '$arrname' matches '$name'"
set name $match
}
return $name
}
proc getEqArrayKeyProc {arrname name} {
set icase [isIcase]
upvar $arrname arr
lassign [getModuleVersSpec $name] mod modname cmpspec versspec modnamere\
modescglob modroot variantlist modnvspec
# check name eventual icase match
set mod [getArrayKey arr [string trimright $mod /] $icase]
if {$mod ne {} && [info exists arr($mod)]} {
set match $mod
} else {
set mlist {}
foreach elt [array names arr] {
if {[modEq $name $elt]} {
lappend mlist $elt
}
}
# must have a default part of result even if only one result
if {[llength $mlist] >= 1} {
# get corresponding icase parent directory
set pname [getArrayKey arr $modname $icase]
if {[info exists arr($pname)]} {
set dfl $pname/[lindex $arr($pname) 1]
}
# resolve symbolic version entries
foreach elt $mlist {
if {[lindex $arr($elt) 0] eq {version}} {
lappend mrlist [lindex $arr($elt) 1]
} else {
lappend mrlist $elt
}
}
if {[info exists dfl] && $dfl in $mrlist} {
set match $dfl
} else {
# raise error as no default part of result
upvar retlist retlist
set retlist [list {} $modnvspec $name none "No default version\
defined for '$name'"]
}
}
}
if {[info exists match]} {
reportDebug "key '$match' in array '$arrname' matches '$name'"
set name $match
}
return $name
}
# Check a module name does match query at the depth level expressed in query
# when search mode is not contains. Define procedure on the fly to adapt its
# code to search configuration option and querydepth and test mode params.
proc defineDoesModMatchAtDepthProc {contains querydepth test} {
set procprops $contains:$querydepth:$test
# define proc if not done yet or if it was defined for another context
if {[info procs doesModMatchAtDepth] eq {} ||\
$::g_doesModMatchAtDepth_procprops ne $procprops} {
if {[info exists ::g_doesModMatchAtDepth_procprops]} {
# remove existing debug trace if any
initProcReportTrace remove doesModMatchAtDepth
rename ::doesModMatchAtDepth {}
}
set ::g_doesModMatchAtDepth_procprops $procprops
# define optimized procedure
if {$contains} {
set atdepth {$mod}
} else {
set atdepth "\[join \[lrange \[split \$mod /\] 0 $querydepth\] /\]"
}
##nagelfar syntax doesModMatchAtDepth x
##nagelfar ignore Non constant argument to proc
proc doesModMatchAtDepth {mod} "return \[modEqStatic $atdepth $test *\]"
# set report traces if some debug mode enabled
initProcReportTrace add doesModMatchAtDepth
}
}
# Define procedure to check module version equals pattern. Adapt procedure
# code whether icase and extended_default are enabled or disabled
proc defineModVersCmpProc {icase extdfl} {
set procname modVersCmpProc
if {$icase} {
append procname Icase
}
if {$extdfl} {
append procname Extdfl
}
# define proc if not done yet or if it was defined for another context
if {[info procs modVersCmp] eq {} || $::g_modVersCmp_proc ne $procname} {
if {[info exists ::g_modVersCmp_proc]} {
# remove existing debug trace if any
initProcReportTrace remove modVersCmp
rename ::modVersCmp ::$::g_modVersCmp_proc
}
##nagelfar syntax modVersCmp x x x x x?
rename ::$procname ::modVersCmp
# set report traces if some debug mode enabled
initProcReportTrace add modVersCmp
set ::g_modVersCmp_proc $procname
}
}
# alternative definitions of modVersCmp proc
proc modVersCmpProc {cmpspec versspec modvers test {psuf {}}} {
set ret 0
switch -- $cmpspec {
in {
# check each verspec in list until match
foreach inspec $versspec {
lassign $inspec incmp invers
if {[set ret [modVersCmp $incmp $invers $modvers $test $psuf]]} {
break
}
}
}
eq {
append versspec $psuf
if {$test eq {eqstart}} {
set ret [string equal -length [string length $versspec/]\
$versspec/ $modvers/]
} else {
##nagelfar ignore Non static subcommand
set ret [string $test $versspec $modvers]
}
}
ge {
# as we work here on a version range: psuf suffix is ignored, checks
# are always extended_default-enabled (as 1.2 includes 1.2.12 for
# instance) and equal, eqstart and match tests are equivalent
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$versspec] != -1 || [string match $versspec.* $modvers])}]
}
le {
# 'ge' comment also applies here
set ret [expr {[isVersion $modvers] && ([versioncmp $versspec\
$modvers] != -1 || [string match $versspec.* $modvers])}]
}
be {
# 'ge' comment also applies here
lassign $versspec lovers hivers
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$lovers] != -1 || [string match $lovers.* $modvers]) &&\
([versioncmp $hivers $modvers] != -1 || [string match\
$hivers.* $modvers])}]
}
}
return $ret
}
proc modVersCmpProcIcase {cmpspec versspec modvers test {psuf {}}} {
set ret 0
switch -- $cmpspec {
in {
foreach inspec $versspec {
lassign $inspec incmp invers
if {[set ret [modVersCmp $incmp $invers $modvers $test $psuf]]} {
break
}
}
}
eq {
append versspec $psuf
if {$test eq {eqstart}} {
set ret [string equal -nocase -length [string length $versspec/]\
$versspec/ $modvers/]
} else {
##nagelfar ignore Non static subcommand
set ret [string $test -nocase $versspec $modvers]
}
}
ge {
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$versspec] != -1 || [string match -nocase $versspec.* $modvers])}]
}
le {
set ret [expr {[isVersion $modvers] && ([versioncmp $versspec\
$modvers] != -1 || [string match -nocase $versspec.* $modvers])}]
}
be {
lassign $versspec lovers hivers
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$lovers] != -1 || [string match $lovers.* $modvers]) &&\
([versioncmp $hivers $modvers] != -1 || [string match -nocase\
$hivers.* $modvers])}]
}
}
return $ret
}
proc modVersCmpProcExtdfl {cmpspec versspec modvers test {psuf {}}} {
set ret 0
switch -- $cmpspec {
in {
foreach inspec $versspec {
lassign $inspec incmp invers
if {[set ret [modVersCmp $incmp $invers $modvers $test $psuf]]} {
break
}
}
}
eq {
append versspec $psuf
if {$test eq {eqstart}} {
set ret [string equal -length [string length $versspec/]\
$versspec/ $modvers/]
} else {
##nagelfar ignore Non static subcommand
set ret [string $test $versspec $modvers]
}
if {!$ret && [string match $versspec.* $modvers]} {
set ret 1
}
}
ge {
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$versspec] != -1 || [string match $versspec.* $modvers])}]
}
le {
set ret [expr {[isVersion $modvers] && ([versioncmp $versspec\
$modvers] != -1 || [string match $versspec.* $modvers])}]
}
be {
lassign $versspec lovers hivers
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$lovers] != -1 || [string match $lovers.* $modvers]) &&\
([versioncmp $hivers $modvers] != -1 || [string match\
$hivers.* $modvers])}]
}
}
return $ret
}
proc modVersCmpProcIcaseExtdfl {cmpspec versspec modvers test {psuf {}}} {
set ret 0
switch -- $cmpspec {
in {
foreach inspec $versspec {
lassign $inspec incmp invers
if {[set ret [modVersCmp $incmp $invers $modvers $test $psuf]]} {
break
}
}
}
eq {
append versspec $psuf
if {$test eq {eqstart}} {
set ret [string equal -nocase -length [string length $versspec/]\
$versspec/ $modvers/]
} else {
##nagelfar ignore Non static subcommand
set ret [string $test -nocase $versspec $modvers]
}
if {!$ret && [string match -nocase $versspec.* $modvers]} {
set ret 1
}
}
ge {
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$versspec] != -1 || [string match -nocase $versspec.* $modvers])}]
}
le {
set ret [expr {[isVersion $modvers] && ([versioncmp $versspec\
$modvers] != -1 || [string match -nocase $versspec.* $modvers])}]
}
be {
lassign $versspec lovers hivers
set ret [expr {[isVersion $modvers] && ([versioncmp $modvers\
$lovers] != -1 || [string match $lovers.* $modvers]) &&\
([versioncmp $hivers $modvers] != -1 || [string match -nocase\
$hivers.* $modvers])}]
}
}
return $ret
}
proc modVariantCmp {pvrlist modvrlist {missmean 0}} {
set ret 1
# missing variant in mod spec means default value
if {$missmean == 1} {
foreach {modvrname modvrval modvrisdfl} $modvrlist {
set modvrarr($modvrname) $modvrval
set modvrisdflarr($modvrname) $modvrisdfl
}
} else {
array set modvrarr $modvrlist
# if missmean == 2 pattern is mod, thus missing variant on mod is ok
# it is used for extra specifier where pattern is definition inside
# modulefile and mod is extra specifier defined on command line
}
foreach pvr $pvrlist {
set pvrarr([lindex $pvr 0]) [lindex $pvr 3]
}
# no match if a specified variant is not found among module variants (and
# if miss is not ok) or if the value differs
foreach vrname [array names pvrarr] {
if {(![info exists modvrarr($vrname)] && $missmean != 2) || ([info\
exists modvrarr($vrname)] && $pvrarr($vrname) ne\
$modvrarr($vrname))} {
set ret 0
break
}
}
# if an unset variant on pattern means variant default value pattern and
# mod are not equal if variant unset on pattern and non-default value is
# set for variant on mod
if {$missmean == 1} {
foreach vrname [array names modvrisdflarr] {
if {!$modvrisdflarr($vrname) && ![info exists pvrarr($vrname)]} {
set ret 0
break
}
}
}
return $ret
}
# Setup a hardwire version of modEq procedure called modEqStatic. This
# optimized procedure already knows the module pattern to compare to, whose
# specification has already been resolved at procedure definition time, which
# saves lot of processing time.
# modEqStatic does not compare against loaded modules so it has no need to
# compare variants set on module specification
proc defineModEqStaticProc {icase extdfl modspec} {
set procprops $icase:$extdfl:$modspec
# define proc if not done yet or if it was defined for another context
if {[info procs modEqStatic] eq {} || $::g_modEqStatic_procprops ne\
$procprops} {
if {[info exists ::g_modEqStatic_procprops]} {
# remove existing debug trace if any
initProcReportTrace remove modEqStatic
rename ::modEqStatic {}
}
set ::g_modEqStatic_procprops $procprops
# define optimized procedure
lassign [getModuleVersSpec $modspec] pmod pmodname cmpspec versspec\
pmodnamere pmodescglob
# trim dup trailing / char and adapt pmod suffix if it starts with /
if {[string index $pmod end] eq {/}} {
set pmod [string trimright $pmod /]/
set endwslash 1
} else {
set endwslash 0
}
set nocasearg [expr {$icase ? {-nocase } : {}}]
set pmodnameslen [string length $pmodname/]
if {$pmod ne {} || $modspec eq {}} {
set procbody "
set pmod {$pmod}
if {\$psuf ne {}} {
if {$endwslash && \[string index \$psuf 0\] eq {/}} {
append pmod \[string range \$psuf 1 end\]
} else {
append pmod \$psuf
}
}
if {\$test eq {eqstart}} {
set ret \[string equal $nocasearg-length \[string length\
\$pmod/\] \$pmod/ \$mod/\]
} else {
if {\$test eq {matchin}} {
set test match
set pmod *\$pmod
}
set ret \[string \$test $nocasearg\$pmod \$mod\]
}"
if {$extdfl} {
append procbody "
if {!\$ret && \[string first / \$pmod\] != -1} {
if {\$test eq {match}} {
set pmodextdfl \$pmod.*
} else {
set pmodextdfl {$pmodescglob.*}
}
set ret \[string match $nocasearg\$pmodextdfl \$mod\]
}"
}
} else {
set procbody "
set pmodname {$pmodname}
set pmodnamere {$pmodnamere}
if {\$test eq {matchin}} {
set test match
if {\$pmodnamere ne {}} {
set pmodnamere .*\$pmodnamere
} else {
set pmodnamere {.*$pmodname}
}
}
if {(\$pmodnamere ne {} && \$test eq {match} && \[regexp\
$nocasearg (^\$pmodnamere)/ \$mod/ rematch pmodname\]) ||\
\[string equal $nocasearg -length $pmodnameslen {$pmodname/}\
\$mod/\]} {
set modvers \[string range \$mod \[string length \$pmodname/\]\
end\]
set ret \[modVersCmp {$cmpspec} {$versspec} \$modvers \$test\
\$psuf\]
} else {
set ret 0
}"
}
append procbody "
return \$ret"
##nagelfar syntax modEqStatic x x? x?
##nagelfar ignore Non constant argument to proc
proc modEqStatic {mod {test equal} {psuf {}}} $procbody
# set report traces if some debug mode enabled
initProcReportTrace add modEqStatic
}
}
# Define procedure to check module name equals pattern. Adapt procedure
# code whether icase and extended_default are enabled or disabled
proc defineModEqProc {icase extdfl} {
set procname modEqProc
if {$icase} {
append procname Icase
}
if {$extdfl} {
append procname Extdfl
}
# define proc if not done yet or if it was defined for another context
if {[info procs modEq] eq {} || $::g_modEq_proc ne $procname} {
if {[info exists ::g_modEq_proc]} {
# remove existing debug trace if any
initProcReportTrace remove modEq
rename ::modEq ::$::g_modEq_proc
# drop existing mem cache
array unset ::g_modEqMemCache
}
##nagelfar syntax modEq x x x? x? x? x? x? x?
rename ::$procname ::modEq
# set report traces if some debug mode enabled
initProcReportTrace add modEq
set ::g_modEq_proc $procname
}
}
# alternative definitions of modEq proc
proc modEqProc {pattern mod {test equal} {trspec 1} {ismodlo 0} {vrcmp 0}\
{modvrlist 0} {psuf {}}} {
# return cached result if any and not checking loaded mod
set searchid $pattern:$mod:$test:$trspec:$vrcmp:$modvrlist:$psuf
if {!$ismodlo && [info exists ::g_modEqMemCache($searchid)]} {
return $::g_modEqMemCache($searchid)
}
# extract specified module name from name and version spec
if {$trspec} {
lassign [getModuleVersSpec $pattern] pmod pmodname cmpspec versspec\
pmodnamere pmodescglob pmodroot pvrlist
} else {
set pmod $pattern
}
# trim dup trailing / char and adapt pmod suffix if it starts with /
set endwslash 0
if {[string index $pmod end] eq {/}} {
# trailing / will be automatically added in the eqstart tests
if {$test eq {eqstart}} {
set pmod [string trimright $pmod /]
} else {
set pmod [string trimright $pmod /]/
set endwslash 1
}
}
# get alternative names if mod is loading(1) or loaded(2)
set altlist [switch -- $ismodlo {
7 {getLoadedAltname $mod {alias}}
6 {getLoadedAltname $mod {sym autosym}}
5 {getAvailListFromVersSpec $mod}
4 {getAllModuleResolvedName $mod 0 {} 1}
3 {getLoadedAltAndSimplifiedName $mod}
2 {getLoadedAltname $mod}
1 {getAllModuleResolvedName $mod}
0 {list}}]
# fetch variant definition from spec if not loaded/loading
if {$vrcmp && $ismodlo in {0 5}} {
set modvrlist [getVariantList $mod 0 0 1]
set mod [getModuleNameAndVersFromVersSpec $mod]
}
# specified module can be translated in a simple mod name/vers or is empty
if {$pmod ne {} || $pattern eq {}} {
if {$psuf ne {}} {
if {$endwslash && [string index $psuf 0] eq {/}} {
append pmod [string range $psuf 1 end]
} else {
append pmod $psuf
}
}
if {$test eq {eqstart}} {
set ret [string equal -length [string length $pmod/] $pmod/ $mod/]
# apply comparison to alternative names if any and no match for mod
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
if {[set ret [string equal -length [string length $pmod/]\
$pmod/ $alt/]]} {
break
}
}
}
} else {
# contains test
if {$test eq {matchin}} {
set test match
set pmod *$pmod
} elseif {$test eq {eqspec}} {
set test equal
}
##nagelfar ignore Non static subcommand
set ret [string $test $pmod $mod]
# apply comparison to alternative names if any and no match for mod
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
##nagelfar ignore Non static subcommand
if {[set ret [string $test $pmod $alt]]} {
break
}
}
}
}
} elseif {$test eq {eqspec}} {
# test equality against all version described in spec (list or range
# boundaries), trspec is considered enabled and psuf empty
foreach pmod [getAllModulesFromVersSpec $pattern] {
if {[set ret [string equal $pmod $mod]]} {
break
}
}
} else {
# contains test
if {$test eq {matchin}} {
set test match
if {$pmodnamere ne {}} {
set pmodnamere .*$pmodnamere
} else {
set pmodnamere .*$pmodname
}
}
# for more complex specification, first check if module name matches
# use a regexp test if module name contains wildcard characters
if {($pmodnamere ne {} && $test eq {match} && [regexp (^$pmodnamere)/\
$mod/ rematch pmodname]) || [string equal -length [string length\
$pmodname/] $pmodname/ $mod/]} {
# then compare versions
set modvers [string range $mod [string length $pmodname/] end]
set ret [modVersCmp $cmpspec $versspec $modvers $test $psuf]
} else {
set ret 0
}
# apply comparison to alternative names if any and no match for mod
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
if {($pmodnamere ne {} && $test eq {match} && [regexp\
(^$pmodnamere)/ $alt/ rematch pmodname]) || [string equal\
-length [string length $pmodname/] $pmodname/ $alt/]} {
# then compare versions
set modvers [string range $alt [string length $pmodname/] end]
if {[set ret [modVersCmp $cmpspec $versspec $modvers $test\
$psuf]]} {
break
}
}
}
}
}
# check if variant specified matches those of selected loaded/ing module
if {$ret && $vrcmp && $ismodlo ni {3 5} && [llength $pvrlist]} {
if {$modvrlist eq {0}} {
set modvrlist [getVariantList $mod]
}
set ret [modVariantCmp $pvrlist $modvrlist]
# variant miss means variant default val when comparing collection content
} elseif {$ret && $vrcmp && $ismodlo == 3} {
set ret [modVariantCmp $pvrlist [getVariantList $mod 3] 1]
# variant miss is ok when comparing an extra specifier passed as mod
} elseif {$ret && $vrcmp && $ismodlo == 5} {
set ret [modVariantCmp $pvrlist $modvrlist 2]
}
if {!$ismodlo} {
set ::g_modEqMemCache($searchid) $ret
}
return $ret
}
proc modEqProcIcase {pattern mod {test equal} {trspec 1} {ismodlo 0} {vrcmp\
0} {modvrlist 0} {psuf {}}} {
set searchid $pattern:$mod:$test:$trspec:$vrcmp:$modvrlist:$psuf
if {!$ismodlo && [info exists ::g_modEqMemCache($searchid)]} {
return $::g_modEqMemCache($searchid)
}
if {$trspec} {
lassign [getModuleVersSpec $pattern] pmod pmodname cmpspec versspec\
pmodnamere pmodescglob pmodroot pvrlist
} else {
set pmod $pattern
}
set endwslash 0
if {[string index $pmod end] eq {/}} {
if {$test eq {eqstart}} {
set pmod [string trimright $pmod /]
} else {
set pmod [string trimright $pmod /]/
set endwslash 1
}
}
set altlist [switch -- $ismodlo {
7 {getLoadedAltname $mod {alias}}
6 {getLoadedAltname $mod {sym autosym}}
5 {getAvailListFromVersSpec $mod}
4 {getAllModuleResolvedName $mod 0 {} 1}
3 {getLoadedAltAndSimplifiedName $mod}
2 {getLoadedAltname $mod}
1 {getAllModuleResolvedName $mod}
0 {list}}]
if {$vrcmp && $ismodlo in {0 5}} {
set modvrlist [getVariantList $mod 0 0 1]
set mod [getModuleNameAndVersFromVersSpec $mod]
}
if {$pmod ne {} || $pattern eq {}} {
if {$psuf ne {}} {
if {$endwslash && [string index $psuf 0] eq {/}} {
append pmod [string range $psuf 1 end]
} else {
append pmod $psuf
}
}
if {$test eq {eqstart}} {
set ret [string equal -nocase -length [string length $pmod/] $pmod/\
$mod/]
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
if {[set ret [string equal -nocase -length [string length\
$pmod/] $pmod/ $alt/]]} {
break
}
}
}
} else {
# contains test
if {$test eq {matchin}} {
set test match
set pmod *$pmod
} elseif {$test eq {eqspec}} {
set test equal
}
##nagelfar ignore Non static subcommand
set ret [string $test -nocase $pmod $mod]
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
##nagelfar ignore Non static subcommand
if {[set ret [string $test -nocase $pmod $alt]]} {
break
}
}
}
}
} elseif {$test eq {eqspec}} {
# test equality against all version described in spec (list or range
# boundaries), trspec is considered enabled and psuf empty
foreach pmod [getAllModulesFromVersSpec $pattern] {
if {[set ret [string equal -nocase $pmod $mod]]} {
break
}
}
} else {
# contains test
if {$test eq {matchin}} {
set test match
if {$pmodnamere ne {}} {
set pmodnamere .*$pmodnamere
} else {
set pmodnamere .*$pmodname
}
}
# for more complex specification, first check if module name matches
# use a regexp test if module name contains wildcard characters
if {($pmodnamere ne {} && $test eq {match} && [regexp -nocase\
(^$pmodnamere)/ $mod/ rematch pmodname]) || [string equal -nocase\
-length [string length $pmodname/] $pmodname/ $mod/]} {
# then compare versions
set modvers [string range $mod [string length $pmodname/] end]
set ret [modVersCmp $cmpspec $versspec $modvers $test $psuf]
} else {
set ret 0
}
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
if {($pmodnamere ne {} && $test eq {match} && [regexp -nocase\
(^$pmodnamere)/ $alt/ rematch pmodname]) || [string equal\
-nocase -length [string length $pmodname/] $pmodname/ $alt/]} {
# then compare versions
set modvers [string range $alt [string length $pmodname/] end]
if {[set ret [modVersCmp $cmpspec $versspec $modvers $test\
$psuf]]} {
break
}
}
}
}
}
if {$ret && $vrcmp && $ismodlo ni {3 5} && [llength $pvrlist]} {
if {$modvrlist eq {0}} {
set modvrlist [getVariantList $mod]
}
set ret [modVariantCmp $pvrlist $modvrlist]
} elseif {$ret && $vrcmp && $ismodlo == 3} {
set ret [modVariantCmp $pvrlist [getVariantList $mod 3] 1]
} elseif {$ret && $vrcmp && $ismodlo == 5} {
set ret [modVariantCmp $pvrlist $modvrlist 2]
}
if {!$ismodlo} {
set ::g_modEqMemCache($searchid) $ret
}
return $ret
}
proc modEqProcExtdfl {pattern mod {test equal} {trspec 1} {ismodlo 0} {vrcmp\
0} {modvrlist 0} {psuf {}}} {
set searchid $pattern:$mod:$test:$trspec:$vrcmp:$modvrlist:$psuf
if {!$ismodlo && [info exists ::g_modEqMemCache($searchid)]} {
return $::g_modEqMemCache($searchid)
}
if {$trspec} {
lassign [getModuleVersSpec $pattern] pmod pmodname cmpspec versspec\
pmodnamere pmodescglob pmodroot pvrlist
} else {
set pmod $pattern
}
set endwslash 0
if {[string index $pmod end] eq {/}} {
if {$test eq {eqstart}} {
set pmod [string trimright $pmod /]
} else {
set pmod [string trimright $pmod /]/
set endwslash 1
}
}
set altlist [switch -- $ismodlo {
7 {getLoadedAltname $mod {alias}}
6 {getLoadedAltname $mod {sym autosym}}
5 {getAvailListFromVersSpec $mod}
4 {getAllModuleResolvedName $mod 0 {} 1}
3 {getLoadedAltAndSimplifiedName $mod}
2 {getLoadedAltname $mod}
1 {getAllModuleResolvedName $mod}
0 {list}}]
if {$vrcmp && $ismodlo in {0 5}} {
set modvrlist [getVariantList $mod 0 0 1]
set mod [getModuleNameAndVersFromVersSpec $mod]
}
if {$pmod ne {} || $pattern eq {}} {
if {$psuf ne {}} {
if {$endwslash && [string index $psuf 0] eq {/}} {
append pmod [string range $psuf 1 end]
} else {
append pmod $psuf
}
}
if {$test eq {eqstart}} {
set ret [string equal -length [string length $pmod/] $pmod/ $mod/]
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
if {[set ret [string equal -length [string length $pmod/]\
$pmod/ $alt/]]} {
break
}
}
}
} else {
# contains test
if {$test eq {matchin}} {
set test match
set pmod *$pmod
} elseif {$test eq {eqspec}} {
set test equal
set eqspec 1
}
##nagelfar ignore Non static subcommand
set ret [string $test $pmod $mod]
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
##nagelfar ignore Non static subcommand
if {[set ret [string $test $pmod $alt]]} {
break
}
}
}
}
# try the extended default match if not root module and not eqspec test
if {![info exists eqspec] && !$ret && [string first / $pmod] != -1} {
if {$test eq {match}} {
set pmodextdfl $pmod.*
} else {
set pmodextdfl $pmodescglob.*
}
set ret [string match $pmodextdfl $mod]
if {!$ret && [llength $altlist]} {
foreach alt $altlist {
if {[set ret [string match $pmodextdfl $alt]]} {
break
}
}
}
}
} elseif {$test eq {eqspec}} {
# test equality against all version described in spec (list or range
# boundaries), trspec is considered enabled and psuf empty
foreach pmod [getAllModulesFromVersSpec $pattern] {
if {[set ret [string equal $pmod $mod]]} {
break
}
}
} else {
# contains test
if {$test eq {matchin}} {
set test match
if {$pmodnamere ne {}} {
set pmodnamere .*$pmodnamere
} else {
set pmodnamere .*$pmodname
}
}
# for more complex specification, first check if module name matches
# use a regexp test if module name contains wildcard characters
if {($pmodnamere ne {} && $test eq {match} && [regexp (^$pmodnamere)/\
$mod/ rematch pmodname]) || [string equal -length [string length\
$pmodname/] $pmodname/ $mod/]} {
# then compare versions
set modvers [string range $mod [string length $pmodname/] end]
set ret [modVersCmp $cmpspec $versspec $modvers $test $psuf]
} else {