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