_about.tcl 1.6 KB

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