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