better and faster is_xschem_file detection
This commit is contained in:
parent
b01bd1ca60
commit
d3d0b78c08
|
|
@ -4123,6 +4123,7 @@ proc is_xschem_file {f} {
|
|||
set ret 0
|
||||
set score 0
|
||||
set instances 0
|
||||
set symbol 0
|
||||
set nline 0
|
||||
set generator 0
|
||||
if {$a} {
|
||||
|
|
@ -4143,33 +4144,35 @@ proc is_xschem_file {f} {
|
|||
# close $fd
|
||||
# set fd [open "|$f"]
|
||||
set generator 1
|
||||
break
|
||||
# continue
|
||||
}
|
||||
if { [regexp {format *= *"@} $line] } { incr symbol; incr score}
|
||||
if { [regexp {template *= *"} $line] } { incr symbol; incr score}
|
||||
if { [regexp {^[TKFGVSE] \{} $line] } { incr score }
|
||||
if { [regexp {^[BL] +[0-9]+ +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +\{} $line] } {incr score}
|
||||
if { [regexp {^N +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +\{} $line] } {incr score}
|
||||
if { [regexp {^C +\{[^{}]+\} +[-0-9.eE]+ +[-0-9.eE]+ +[0-3]+ +[0-3]+ +\{} $line] } {
|
||||
set symname [regsub {([^{]+{)([^}]+)(}.*)} $line {\2}]
|
||||
set type [xschem get_sym_type $symname]
|
||||
# title/launcher instances in symbols are allowed, do not indicate it is a schematic.
|
||||
if {![regexp "^(logo|launcher)$" $type]} {
|
||||
incr instances
|
||||
incr score
|
||||
if {[regexp {ipin\.sym|opin\.sym|iopin\.sym} $line]} {set symbol 0}
|
||||
}
|
||||
}
|
||||
|
||||
if { [regexp "^v\[ \t\]+\{xschem\[ \t\]+version\[ \t\]*=.*\[ \t\]+file_version\[ \t\]*=" $line] } {
|
||||
set ret 1
|
||||
}
|
||||
if {$instances >= 4} {break}
|
||||
if {$score > 2000} {break} ;# give up on extremely big files
|
||||
incr nline
|
||||
}
|
||||
if { $score > 4 } { set ret 1} ;# Heuristic decision :-)
|
||||
if {$generator eq {1}} {
|
||||
set ret GENERATOR
|
||||
} elseif { $ret ne {0}} {
|
||||
if { $instances} {
|
||||
set ret SCHEMATIC
|
||||
} else {
|
||||
if {$symbol && $instances < 4} {
|
||||
set ret SYMBOL
|
||||
} else {
|
||||
set ret SCHEMATIC
|
||||
}
|
||||
}
|
||||
close $fd
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue