-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_readme.tcl
57 lines (48 loc) · 1.84 KB
/
update_readme.tcl
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
proc update_readme_number { input_file output_file source_file} {
# If the input file can't be opened, return an error.
if { [catch {open $input_file} input] } {
return -code error $input
puts "can't open input"
}
# If the output file can't be opened, return an error
if { [catch {open $output_file w} output] } {
return -code error $output
puts "can't open output"
}
# If the input file can't be opened, return an error.
if { [catch {open $source_file} source] } {
return -code error $source
puts "can't open source"
}
# Read through the input file a line at a time
while {-1 != [gets $source line] } {
if { [regexp {^\s*constant compile_rev : integer := ([[:digit:]]+);\s*$} \ $line match version_number] } {
set minor_compile_ver $version_number
} elseif { [regexp {^\s*constant major_rev : integer := ([[:digit:]]+);\s*$} \ $line match version_number] } {
set major_compile_ver $version_number
} elseif { [regexp {^\s*constant major_rev : integer := -([[:digit:]]+);\s*$} \ $line match version_number] } {
set major_compile_ver "-"
append major_compile_ver $version_number
}
}
set string "Gateware version "
append string $major_compile_ver
append string "."
append string $minor_compile_ver
# throw away first input line, change it with a new string
gets $input line
puts $output $string
# keep all other lines the same
while {-1 != [gets $input line] } {
puts $output $line
}
close $input
close $output
close $source
}
set script_path [file dirname [file normalize [info script]]]
set source_name "[file normalize "$script_path/src/hdl/revision/revisions.vhd"]"
set input_name "[file normalize "$script_path/README.md"]"
set output_name "[file normalize "$script_path/README.md.temp"]"
update_readme_number $input_name $output_name $source_name
file rename -force $output_name $input_name