OXYGENHUB
◆ main openmsx / share / scripts / _about.tcl
1.6 KiB · Tcl · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
namespace eval about {
2
3
set_help_text about \
4
"Shows a list of commands and/or settings that seem related to the given keyword.
5
If there is only one such command or setting the helptext for that command or
6
setting is also shown."
7
8
proc about {keyword} {
9
	openmsx::lazy_execute_all
10
	set command_matches [get_matching_commands $keyword]
11
	set setting_matches [get_matching_settings $keyword]
12
	set result ""
13
	set lc [llength $command_matches]
14
	set ls [llength $setting_matches]
15
	if {$lc == 0  && $ls == 0} {
16
		error "No candidates found."
17
	} elseif {$lc == 1 && $ls == 0} {
18
		set match [lindex $command_matches 0]
19
		append result "Command $match:\n"
20
		append result "[help $match]\n"
21
	} elseif {$lc == 0 && $ls == 1} {
22
		set match [lindex $setting_matches 0]
23
		append result "Setting $match:\n"
24
		append result "[help set $match]\n"
25
	} else {
26
		append result "Multiple candidates found:\n"
27
		foreach match $command_matches {
28
			append result "  command: $match\n"
29
		}
30
		foreach match $setting_matches {
31
			append result "  setting: $match\n"
32
		}
33
	}
34
	return $result
35
}
36
37
proc get_matching_commands {keyword} {
38
	set matches [list]
39
	foreach command [info commands] {
40
		catch {
41
			if {[regexp -nocase -- $keyword [help $command]] ||
42
			    [regexp -nocase -- $keyword $command]} {
43
				lappend matches $command
44
			}
45
		}
46
	}
47
	return $matches
48
}
49
50
proc get_matching_settings {keyword} {
51
	set matches [list]
52
	foreach setting [openmsx_info setting] {
53
		catch {
54
			if {[regexp -nocase -- $keyword [help set $setting]] ||
55
			    [regexp -nocase -- $keyword $setting]} {
56
				lappend matches $setting
57
			}
58
		}
59
	}
60
	return $matches
61
}
62
63
namespace export about
64
65
} ;# namespace about
66
67
namespace import about::*