proc pref_read {} {
global prefs_init_filename env gdb_ImageDir GDBTK_LIBRARY GDBStartup
global tcl_platform
if {[info exists env(HOME)]} {
if {$tcl_platform(platform) == "windows"} {
set home [ide_cygwin_path to_win32 $env(HOME)]
} else {
set home $env(HOME)
}
} else {
set home ""
}
if {$tcl_platform(platform) == "windows"} {
set prefs_init_filename "gdbtk.ini"
} else {
set prefs_init_filename ".gdbtkinit"
}
if {!$GDBStartup(inhibit_prefs)} {
set file_opened 0
if {[file exists $prefs_init_filename]} {
if {[catch {open $prefs_init_filename r} fd]} {
dbug E "$fd"
return
}
set file_opened 1
} elseif {$home != ""} {
set name [file join $home $prefs_init_filename]
if {[file exists $name]} {
if {[catch {open $name r} fd]} {
dbug E "$fd"
return
}
set prefs_init_filename $name
set file_opened 1
}
}
if {$file_opened == "1"} {
set section gdb
set version 0
while {[gets $fd line] >= 0} {
switch -regexp -- $line {
{^[ \t\n]* if {[regexp -- "^# GDBtkInitVersion: (\[0-9\]+)\$" $line \
dummy v]} {
set version $v
}
}
{^[ \t\n]*$} {
; }
{^[ \t\n]*\[.*\]} {
regexp {\[(.*)\]} $line match section
}
{^[ \t\n]*option.*} {
set line [string trimleft $line]
eval $line
}
default {
set a ""
set name ""
set val ""
regexp "\[ \t\n\]*\(.+\)=\(.+\)" $line a name val
if {$a == "" || $name == ""} {
dbug W "Cannot parse line: $line"
} else {
set val [unescape_value $val $version]
if {$section == "gdb"} {
pref setd gdb/$name $val
} elseif {$section == "global" && [regexp "^font/" $name]} {
set name [split $name /]
set f global/
append f [join [lrange $name 1 end] /]
if {[lsearch [font names] $f] == -1} {
eval define_font $f $val
} else {
pref set global/font/[join [lrange $name 1 end] /] $val
}
} elseif {$section == "global"} {
pref setd $section/$name $val
} else {
if {$val == "src-font"} {set val "global/fixed"}
pref setd gdb/$section/$name $val
}
}
}
}
}
close $fd
} elseif {$home != ""} {
set prefs_init_filename [file join $home $prefs_init_filename]
}
set gdb_ImageDir [file join $GDBTK_LIBRARY [pref get gdb/ImageDir]]
}
pref_set_colors $home
}
proc pref_save {{win {}}} {
global prefs_init_filename GDBStartup
if {!$GDBStartup(inhibit_prefs)} {
debug "pref_save $prefs_init_filename"
if {[catch {open $prefs_init_filename w} fd]} {
debug "ERROR: $fd"
return
}
puts $fd "\# GDBtk Init file"
puts $fd {
set plist [pref list]
puts $fd "\[global\]"
foreach var $plist {
set t [split $var /]
if {[lindex $t 0] == "global"} {
set x [join [lrange $t 1 end] /]
set v [escape_value [pref get $var]]
if {$x != "" && $v != ""} {
puts $fd "\t$x=$v"
}
}
}
puts $fd "\[gdb\]"
foreach var $plist {
set t [split $var /]
if {[lindex $t 0] == "gdb"
&& [string compare [join [lreplace $t 0 1] /] ""] == 0} {
set x [lindex $t 1]
set v [escape_value [pref get $var]]
if {$x != "" && $v != ""} {
puts $fd "\t$x=$v"
}
}
}
lappend secs load console src reg stack locals watch bp search \
process geometry help browser kod window session mem
foreach section $secs {
puts $fd "\[$section\]"
foreach var $plist {
set t [split $var /]
if {[lindex $t 0] == "gdb" && [lindex $t 1] == $section} {
set x [join [lrange $t 2 end] /]
set v [escape_value [pref get $var]]
if {$x != "" && $v != ""} {
puts $fd "\t$x=$v"
}
}
}
}
close $fd
}
if {$win != ""} {
$win delete
}
}
proc escape_value {val} {
if {[info tclversion] >= 8.1} {
set expr {([\[\]=%\n])}
} else {
set expr "(\[\]\[=%\n\])"
}
regsub -all -- $expr $val \
{[format "%%%02x" [scan {\1} %c x; set x]]} newval
return [subst -nobackslashes -novariables $newval]
}
proc unescape_value {val version} {
switch -exact -- $version {
0 {
if {[regsub -all -- {!%} $val = newval]} {
return $newval
}
}
1 {
regsub -all -- "%(..)" $val \
{[format %c 0x\1]} newval
return [subst -nobackslashes -novariables $newval]
}
default {
error "Unknown encoding version $version"
}
}
return $val
}
proc pref_set_defaults {} {
global GDBTK_LIBRARY tcl_platform gdb_ImageDir
debug
pref define gdb/ImageDir images2
set gdb_ImageDir [file join $GDBTK_LIBRARY [pref get gdb/ImageDir]]
pref define gdb/font_cache ""
pref define gdb/mode 0; pref define gdb/control_target 1; pref define gdb/B1_behavior 1; pref define gdb/use_icons 1;
if {$tcl_platform(platform) == "windows"} {
pref define gdb/compat "Windows"
} elseif {$tcl_platform(platform) == "unix"} {
pref define gdb/compat "GNOME"
} else {
pref define gdb/compat "default"
}
pref define gdb/load/verbose 0
pref define gdb/load/main 1
pref define gdb/load/exit 1
pref define gdb/load/check 0
pref define gdb/load/bp_at_func 0
pref define gdb/load/bp_func ""
pref define gdb/load/baud 38400
if {$tcl_platform(platform) == "windows"} {
pref define gdb/load/port com1
} else {
pref define gdb/load/port "/dev/ttyS0"
}
pref define gdb/window/active {}
pref define gdb/console/prompt "(gdb) "
pref define gdb/console/deleteLeft 1
pref define gdb/console/wrap 0
pref define gdb/console/prompt_fg DarkGreen
pref define gdb/console/error_fg red
pref define gdb/console/log_fg green
pref define gdb/console/target_fg blue
pref define gdb/console/font global/fixed
pref define gdb/src/PC_TAG green
pref define gdb/src/STACK_TAG gold
pref define gdb/src/BROWSE_TAG \ pref define gdb/src/handlebg red
pref define gdb/src/bp_fg red
pref define gdb/src/temp_bp_fg orange
pref define gdb/src/disabled_fg black
pref define gdb/src/font global/fixed
pref define gdb/src/break_fg black
pref define gdb/src/source2_fg navy
pref define gdb/src/variableBalloons 1
pref define gdb/src/trace_fg magenta
pref define gdb/src/tab_size 8
pref define gdb/src/linenums 1
pref define gdb/src/thread_fg pink
pref define gdb/src/top_control 1;
pref define gdb/src/run_attach 0
pref define gdb/src/run_load 0
pref define gdb/src/run_run 1
pref define gdb/src/run_cont 0
pref define gdb/src/disassembly-flavor ""
pref define gdb/variable/font global/fixed
pref define gdb/variable/disabled_fg gray
pref define gdb/stack/font global/fixed
pref define gdb/reg/rows 16
pref define gdb/global_prefs/save_fg red
pref define gdb/global_prefs/message_fg white
pref define gdb/global_prefs/message_bg red
pref define gdb/search/last_symbol ""
pref define gdb/search/filter_mode "starts with"
pref define gdb/browser/hide_h 0
pref define gdb/browser/layout 2
pref define gdb/bp/show_threads 0
pref define gdb/help/browsername ""
pref define gdb/kod/show_icon 0
pref define gdb/main_names [list main MAIN___ MAIN__ cyg_user_start cyg_start ]
pref define gdb/warnings/signal 0
pref define gdb/mem/size 4
pref define gdb/mem/numbytes 0
pref define gdb/mem/format x
pref define gdb/mem/ascii 1
pref define gdb/mem/ascii_char .
pref define gdb/mem/bytes_per_row 16
pref define gdb/mem/color green
pref define gdb/editor ""
}
proc pref_set_colors {home} {
global Colors tcl_platform
debug
switch [pref get gdb/compat] {
"Windows" {
debug "loading OS colors for Windows"
set Colors(fg) SystemButtonText
set Colors(bg) SystemButtonFace
set Colors(textfg) black
set Colors(textbg) white
set Colors(sfg) SystemHighlightText
set Colors(sbg) SystemHighlight
pref_set_option_db 0
}
"KDE" {
debug "loading OS colors for KDE"
pref_load_default
if {[pref_load_gnome $home [list .gtkrc-kde]]} {
debug "loaded gnome file"
pref_set_option_db 0
debug "loaded option file"
} else {
entry .e
set Colors(textbg) white
set Colors(textfg) black
set Colors(bg) [option get . background {}]
if {$Colors(bg) == ""} {set Colors(bg) lightgray}
set Colors(fg) [option get . foreground {}]
if {$Colors(fg) == ""} {set Colors(fg) black}
set Colors(sbg) [option get .e selectBackground {}]
if {$Colors(sbg) == ""} {set Colors(sbg) blue}
set Colors(sfg) [option get .e selectForeground {}]
if {$Colors(sfg) == ""} {set Colors(sfg) white}
destroy .e
pref_set_option_db 1
}
}
"GNOME" {
pref_load_default
pref_load_gnome $home
pref_set_option_db 0
}
"default" {
pref_load_default
pref_set_option_db 1
}
}
}
proc pref_load_default {} {
global Colors
debug "loading default colors"
set Colors(textbg) white
set Colors(textfg) black
set Colors(bg) lightgray
set Colors(fg) black
set Colors(sbg) blue
set Colors(sfg) white
}
proc pref_load_gnome {home {possible_names {}}} {
debug "loading OS colors for GNOME"
if {$possible_names == ""} {
set possible_names {.gtkrc .gtkrc-1.2-gnome2}
}
set found 0
foreach name $possible_names {
debug "home=$home name=$name"
set fname [file join $home $name]
debug "fname=$fname"
if {[file exists $fname]} {
if {[catch {open $fname r} fd]} {
dbug W "cannot open $fname: $fd"
return 0
}
set found 1
break
}
}
if {$found} {
set found [load_gnome_file $fd]
close $fd
}
return $found
}
proc load_gnome_file {fd} {
global Colors
set found 0
while {[gets $fd line] >= 0} {
if {[regexp {include \"([^\"]*)} $line foo incname]} {
debug "include $incname $found"
if {$found == 0 && [file exists $incname]} {
if {[catch {open $incname r} fd2]} {
dbug W "cannot open $incname: $fd2"
} else {
set found [load_gnome_file $fd2]
close $fd2
if {$found} {
return $found
}
}
}
continue
} elseif {[regexp "\[ \t\n\]*\(.+\) = \(.+\)" $line a name val] == 0} {
continue
}
if {[regexp "\"#......\"" $val a] == 1} {
set val [lindex $a 0]
} else {
set res [scan $val "\{ %f, %f, %f \}" r g b]
if {$res != 3} {
continue
}
set r [expr int($r*255)]
set g [expr int($g*255)]
set b [expr int($b*255)]
set val [format "\#%02x%02x%02x" $r $g $b]
}
debug "name=\"$name\" val=\"$val\""
switch [string trimright $name] {
{bg[NORMAL]} {
set found 1
if {![info exists new(bg)]} {
debug "setting bg to $val"
set new(bg) $val
}
}
{base[NORMAL]} {
}
{text[NORMAL]} {
}
{fg[NORMAL]} {
if {![info exists new(fg)]} {
set new(fg) $val
}
}
{fg[ACTIVE]} {
if {![info exists new(afg)]} {
set new(afg) $val
}
}
{bg[SELECTED]} {
if {![info exists new(sbg)]} {
set new(sbg) $val
}
}
{base[SELECTED]} {
if {![info exists new(sbg)]} {
set new(sbg) $val
}
}
{fg[SELECTED]} {
if {![info exists new(sfg)]} {
set new(sfg) $val
}
}
{fg[INSENSITIVE]} {
if {![info exists new(dfg)]} {
set new(dfg) $val
}
}
{bg[PRELIGHT]} {
set Colors(prelight) $val
}
{base[PRELIGHT]} {
set Colors(prelight) $val
}
}
}
foreach c {fg bg sfg sbg dfg} {
if {[info exists new($c)]} {
set Colors($c) $new($c)
}
}
return 1
}
proc pref_set_option_db {makebg} {
global Colors
set Colors(change) "green"
option add *background $Colors(bg)
option add *Text*background $Colors(textbg)
option add *Entry*background $Colors(textbg)
option add *foreground $Colors(fg)
option add *Text*foreground $Colors(textfg)
option add *Entry*foreground $Colors(textfg)
option add *highlightBackground $Colors(bg)
option add *selectBackground $Colors(sbg)
if {$::tcl_platform(platform) == "unix"} {
option add *activeBackground $Colors(sbg)
}
option add *selectForeground $Colors(sfg)
option add *Menu*activeForeground $Colors(sfg)
if {[info exists Colors(prelight)]} {
option add *Button*activeBackground $Colors(prelight)
}
if {[info exists Colors(dfg)]} {
option add *disabledForeground $Colors(dfg)
}
if {$makebg} {
set bg2 [winfo rgb . $Colors(bg)]
set dbg [format option add *activeBackground $dbg
option add *troughColor $dbg
}
if {$::tcl_platform(platform) == "unix"} {
option add *selectColor $Colors(sbg)
}
}