improved find_file proc, added match_file

This commit is contained in:
Stefan Frederik 2022-10-18 00:02:10 +02:00
parent 33d9afd3a1
commit edd1e3a370
3 changed files with 1969 additions and 1902 deletions

File diff suppressed because it is too large Load Diff

View File

@ -521,6 +521,12 @@
<Component Id="cmp8F4AD0DB3284F789679B6E780DF7616A" Guid="{D1E3D207-F390-4EC5-98AD-6CB883156976}">
<File Id="fil7FED53D0213DE18EF500E91297C9CC8F" KeyPath="yes" Source="$(var.xschemLibrarySrcDir)\examples\poweramp.sym" />
</Component>
<Component Id="cmpA1429BE201EF92EC351528E0BCDB04EF" Guid="{066E2CBB-D1B1-4787-B43F-572780DEF1E5}">
<File Id="filBC7602B7705625867532CF6FBB48CBA6" KeyPath="yes" Source="$(var.xschemLibrarySrcDir)\examples\poweramp_lcc.sch" />
</Component>
<Component Id="cmp5D030C41C051C6E875BF22D01B52B1B2" Guid="{C9D776A6-EBB5-4C64-A3F6-23E1669177CD}">
<File Id="filBAEF75C796F1B31FB9E26315D53B9344" KeyPath="yes" Source="$(var.xschemLibrarySrcDir)\examples\poweramp_lcc.sym" />
</Component>
<Component Id="cmp09E02BBAEBC12A661A112103F3DF3185" Guid="{9FF0B1B3-E625-4557-92D4-252F0CE086E6}">
<File Id="fil83608F795C1EE2C43E91C2D23C10FB68" KeyPath="yes" Source="$(var.xschemLibrarySrcDir)\examples\poweramp_xyce.sch" />
</Component>
@ -5602,6 +5608,8 @@
<ComponentRef Id="cmp11D3F0063EABB6D6807243D2674493C0" />
<ComponentRef Id="cmpDA0059CD9B0B7597A1C2A158F52D6018" />
<ComponentRef Id="cmp8F4AD0DB3284F789679B6E780DF7616A" />
<ComponentRef Id="cmpA1429BE201EF92EC351528E0BCDB04EF" />
<ComponentRef Id="cmp5D030C41C051C6E875BF22D01B52B1B2" />
<ComponentRef Id="cmp09E02BBAEBC12A661A112103F3DF3185" />
<ComponentRef Id="cmp637646145659F3CFFC823F7ABC2FA7E2" />
<ComponentRef Id="cmpAC7AB0F0A898E10C4C4CB75FB9A984E5" />

View File

@ -4326,19 +4326,61 @@ proc viewdata {data {ro {}}} {
return $rcode
}
# find files into $paths directories matching $f
# use $pathlist global search path if $paths empty
# recursively descend directories
proc sub_match_file { f {paths {}} } {
global pathlist match_file_dir_arr
set res {}
if {$paths eq {}} {set paths $pathlist}
foreach i $paths {
foreach j [glob -nocomplain -directory $i *] {
# puts "--> $j $f"
# set jj [regsub {/ $} [file normalize ${j}/\ ] {}]
if {[file isdirectory $j]} {
set jj [regsub {/ $} [file normalize ${j}/\ ] {}]
if {[array names match_file_dir_arr -exact $jj] == {}} {
set match_file_dir_arr($jj) 1
# puts "********** directory $jj"
set sub_res [sub_match_file $f $j] ;# recursive call
if {$sub_res != {} } {eval lappend res $sub_res}
}
} else {
set fname [file tail $j]
if {[regexp $f $fname]} {
lappend res $j
}
}
}
}
return $res
}
proc match_file { f {paths {}} } {
global match_file_dir_arr
catch {unset match_file_dir_arr}
set res [sub_match_file $f $paths]
catch {unset match_file_dir_arr}
return $res
}
# find given file $f into $paths directories
# use $pathlist global search path if $paths empty
# recursively descend directories
proc find_file { f {paths {}} } {
global pathlist
proc sub_find_file { f {paths {}} } {
global pathlist match_file_dir_arr
set res {}
if {$paths eq {}} {set paths $pathlist}
foreach i $paths {
foreach j [glob -nocomplain -directory $i *] {
# puts "--> $j $f"
if {[file isdirectory $j]} {
# puts "directory $j"
set res [find_file $f $j] ;# recursive call
set jj [regsub {/ $} [file normalize ${j}/\ ] {}]
if {[array names match_file_dir_arr -exact $jj] == {}} {
set match_file_dir_arr($jj) 1
# puts "********** directory $jj"
set res [sub_find_file $f $j] ;# recursive call
}
} else {
set fname [file tail $j]
if {$fname == $f} {
@ -4351,6 +4393,15 @@ proc find_file { f {paths {}} } {
return $res
}
proc find_file { f {paths {}} } {
global match_file_dir_arr
catch {unset match_file_dir_arr}
set res [sub_find_file $f $paths]
catch {unset match_file_dir_arr}
return $res
}
# given an absolute path of a symbol/schematic remove the path prefix
# if file is in a library directory (a $pathlist dir)
proc rel_sym_path {symbol} {