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
|
#!/usr/bin/env tclsh
proc putRange {field minimum maximum isAngle} {
if {$isAngle} {
set format "%u"
} else {
set format "%.2f"
append minimum ".0"
append maximum ".0"
set minimum [expr {$minimum / 100.0}]
set maximum [expr {$maximum / 100.0}]
}
puts $::outputStream [format " .%s = \{.minimum=$format, .maximum=$format\}," $field $minimum $maximum]
}
set inputFile "colors"
set outputFile "colors.out"
set inputStream [open $inputFile {RDONLY}]
set outputStream [open $outputFile {CREAT TRUNC WRONLY}]
set first true
while {[gets $inputStream inputLine] >= 0} {
if {[regexp {^Color: +(.*?), +Hue:(.*?), +Sat:(.*?), +Val: +(.*?)( .*)?$} $inputLine x color hue sat val comment]} {
lassign [split $hue -] hueMin hueMax
lassign [split $sat -] satMin satMax
lassign [split $val -] valMin valMax
if {$first} {
set first false
} else {
puts $outputStream ""
}
puts $outputStream " \{ .name = \"$color\","
putRange "hue" $hueMin $hueMax true
putRange "sat" $satMin $satMax false
putRange "val" $valMin $valMax false
puts $outputStream " \},"
} else {
puts $inputLine
}
}
close $inputStream
close $outputStream
exit 0
|