OXYGENHUB
◆ main openmsx / share / scripts / breakpoints.tcl
1.9 KiB · Tcl · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
# Easily save breakpoints to and restore from a file
2
3
proc get_breakpoints_dir {} {
4
	set path [file normalize $::env(OPENMSX_USER_DATA)/../breakpoints]
5
	file mkdir $path
6
	return $path
7
}
8
9
namespace eval breakpoints {
10
11
proc fix_extension {filename} {
12
	expr {[string match *.breakpoints $filename] ? $filename : "$filename.breakpoints"}
13
}
14
15
proc fix_filename {filename} {
16
	file join [get_breakpoints_dir] [fix_extension $filename]
17
}
18
19
proc get_breakpoints_dir_help {args} {
20
	return \
21
{get_breakpoints_dir
22
23
Returns breakpoint directory for this user.
24
}}
25
set_help_proc get_breakpoints_dir breakpoints::get_breakpoints_dir_help
26
27
proc save_breakpoints_help {args} {
28
	return \
29
{save_breakpoints <filename>
30
31
Saves all breakpoint subtypes (breakpoints, watchpoint, conditions) to a given file.
32
}}
33
set_help_proc save_breakpoints breakpoints::save_breakpoints_help
34
35
proc load_breakpoints_help {args} {
36
	return \
37
{load_breakpoints <filename>
38
39
Loads all breakpoint subtypes (breakpoints, watchpoints and conditions) from a given file.
40
}}
41
set_help_proc load_breakpoints breakpoints::load_breakpoints_help
42
43
}
44
45
proc save_breakpoints {filename} {
46
	set fh [open [breakpoints::fix_filename $filename] "w"]
47
	foreach type {breakpoint watchpoint condition} {
48
		puts $fh "\[$type\]\n[join [dict values [debug $type list]] \n]\n"
49
	}
50
	close $fh
51
}
52
53
proc load_breakpoints {filename} {
54
	foreach type {breakpoint watchpoint condition} {
55
		set existing_bps($type) [dict values [debug $type list]]
56
	}
57
	set section {}
58
	set fh [open [breakpoints::fix_filename $filename] "r"]
59
	foreach line [split [read -nonewline $fh] \n] {
60
		set line [string trim $line]
61
		# load valid file section only
62
		if {[regexp {^\[([^\]]+)\]$} $line -> section]} continue
63
		if {!($section in {breakpoint watchpoint condition})} continue
64
		# compare and create breakpoints if not found
65
		if {$line eq {} || $line in $existing_bps($section)} continue
66
		debug $section create {*}$line
67
	}
68
	close $fh
69
}