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