mkopts.tcl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/tclsh
  2. #
  3. # This script is used to generate the array of strings and the enum
  4. # that appear at the beginning of the C code implementation of a
  5. # a TCL command and that define the available subcommands for that
  6. # TCL command.
  7. set prefix {}
  8. while {![eof stdin]} {
  9. set line [gets stdin]
  10. if {$line==""} continue
  11. regsub -all "\[ \t\n,\]+" [string trim $line] { } line
  12. foreach token [split $line { }] {
  13. if {![regexp {(([a-zA-Z]+)_)?([_a-zA-Z0-9]+)} $token all px p2 name]} continue
  14. lappend namelist [string tolower $name]
  15. if {$px!=""} {set prefix $p2}
  16. }
  17. }
  18. puts " static const char *${prefix}_strs\[\] = \173"
  19. set col 0
  20. proc put_item x {
  21. global col
  22. if {$col==0} {puts -nonewline " "}
  23. if {$col<2} {
  24. puts -nonewline [format " %-25s" $x]
  25. incr col
  26. } else {
  27. puts $x
  28. set col 0
  29. }
  30. }
  31. proc finalize {} {
  32. global col
  33. if {$col>0} {puts {}}
  34. set col 0
  35. }
  36. foreach name [lsort $namelist] {
  37. put_item \"$name\",
  38. }
  39. put_item 0
  40. finalize
  41. puts " \175;"
  42. puts " enum ${prefix}_enum \173"
  43. foreach name [lsort $namelist] {
  44. regsub -all {@} $name {} name
  45. put_item ${prefix}_[string toupper $name],
  46. }
  47. finalize
  48. puts " \175;"