file A : PIN X DIRE ; USE ; PORT LAYER M7 ; RECT 1 2 3 4 ; END END X PIN Y DIRE ; USE ; PORT LAYER M7 ; RECT 3 4 5 6 ; END END X file B : X Y create a script by TCL , this script will convert file A to file B .
时间: 2024-01-12 07:03:25 浏览: 20
Here's a TCL script that will convert file A to file B:
```
# Open file A for reading
set a_file [open "file_A" r]
# Open file B for writing
set b_file [open "file_B" w]
# Loop through each line of file A
while {[gets $a_file line] != -1} {
# Remove any leading/trailing whitespace
set line [string trim $line]
# Check if the line is a PIN declaration
if {[string match "PIN *" $line]} {
# Get the pin name
set pin_name [string trim [lindex [split $line] 1]]
# Write the pin declaration to file B
puts $b_file "$pin_name"
}
# Check if the line is a RECT declaration
if {[string match "RECT *" $line]} {
# Get the rectangle coordinates
set coords [string trim [lrange [split $line] 1 end]]
# Write the rectangle declaration to file B
puts -nonewline $b_file " $coords;"
}
# Check if the line is an END statement
if {[string match "END *" $line]} {
# Write the END statement to file B
puts $b_file ""
}
}
# Close the files
close $a_file
close $b_file
```
This script will read each line of file A, extract the PIN and RECT declarations, and write them to file B in the desired format. Note that this script assumes that file A only contains PIN and RECT declarations, and that the PIN declarations come before the RECT declarations. If your actual files are more complex, you may need to modify the script accordingly.