Hello all,
Previous on a different machine in a land far far away I've implemented this.
However I can't recall how to do it. The ; was previously attached to the number which made it even more complicated.
I would like to take this line
constant FIRMWARE_VERSION_C : integer := 71 ;
and turn it into the following
constant FIRMWARE_VERSION_C : integer := 72 ;
Code TCL - [expand] |
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
| set filename "./hdl/FWKS_PIU_PKG.vhd"
set filename2 "./hdl/FWKS_PIU_PKG_temp.vhd"
set f [open $filename]
set f2 [open $filename2 w]
set content [read $f]
set lines [split $content "\n"]
foreach line $lines {
if [regexp "FIRMWARE_VERSION_C" $line] {
set a [lindex [split $line] end]
# set b [expr {int($a) +1}]; #kinda works
# lreplace $line end-1 end-1 $b
# puts $f2 $line
puts $f2 $a
} else {
puts $f2 $line
}
}
# It is important to not lock out the file
close $f
close $f2 |
When I try the line replacement my tcl compiler in libero is saying "[ Line 12: expected number but got ":=" ]" - which is the foreach line.
- - - Updated - - -
FYI.
Error mentioned above brought about by line in the original file which didn't have space between number and ";"
-- constant FIRMWARE_VERSION_C : integer := 72;
Now it will run but not update the number!
- - - Updated - - -
Solved own question, however would appreciate if anyone knows of a better way of doing this.
Code TCL - [expand] |
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
| set filename "./hdl/FWKS_PIU_PKG.vhd"
set filename2 "./hdl/FWKS_PIU_PKG_temp.vhd"
set f [open $filename]
set f2 [open $filename2 w]
set content [read $f]
close $f
set lines [split $content "\n"]
foreach line $lines {
if [regexp "FIRMWARE_VERSION_C" $line] {
set a [lindex [split $line] end-1]
set b [expr {int($a)+1}]
# set line2 [lreplace $line end-1 end "$b ;"]
# lreplace $line end-1 end "$b ;"
# lreplace $line end-1 end {$b ;}
lreplace $line end-1 end-1 {$b}
puts $f2 $line
} else {
puts $f2 $line
}
}
# It is important to not lock out the file
close $f2 |