+proc get_total_drills {drill_count_dict} {
+ # Return the total number of drills in the drill count dictionary
+ # drill_count_dict -- Dictionary of (tool code) : (tool count)
+ foreach tool [dict keys $drill_count_dict] {
+ incr total_drills [dict get $drill_count_dict $tool]
proc write_drill_table {drill_diameter_dict drill_count_dict drill_units} {
# Write a pipe-delimited drill table
- set separator "|-[string repeat - $tool_width]-"
+ set separator [string repeat " " $total_width]
+ append separator "|-[string repeat - $tool_width]-"
append separator "+-[string repeat - $size_width]-"
append separator "+-[string repeat - $count_width]-"
append separator "+-[string repeat - $filled_width]-"
- puts [format "| %-*s | %-*s | %-*s | %-*s | " \
- $size_width "Hole size ($drill_units)" \
- $filled_width "Filled?"
+ set header [string repeat " " $total_width]
+ append header [format "| %-*s | %-*s | %-*s | %-*s | " \
+ $size_width "Hole size ($drill_units)" \
+ $filled_width "Filled?"
foreach tool [dict keys $drill_diameter_dict] {
if {[string first $tool $params(t)] != -1} {
- puts [format "| %-*s | %-*s | %-*s | %-*s | " $tool_width $tool \
- $size_width [dict get $drill_diameter_dict $tool] \
- $count_width [dict get $drill_count_dict $tool] \
+ set table_row [string repeat " " $total_width]
+ append table_row [format "| %-*s | %-*s | %-*s | %-*s | " $tool_width $tool \
+ $size_width [dict get $drill_diameter_dict $tool] \
+ $count_width [dict get $drill_count_dict $tool] \
+ set total_row [format "%-*s" $total_width "Total:"]
+ append total_row [format "| %-*s | %-*s | %-*s | %-*s | " \
+ $tool_width [llength [dict keys $drill_diameter_dict]] \
+ $count_width [get_total_drills $drill_count_dict] \
# Start processing the file