Makefile: add pickrand
[cmccabe-bin] / define-to-enum.rb
1 #!/usr/bin/ruby -w
2
3 require 'optparse'
4 require 'ostruct'
5 require 'pp'
6
7 ##################### CLASSES ##################### 
8 class MyOptionParse
9   def self.parse(args)
10     # default values 
11     opts = OpenStruct.new
12     opts.width = 70
13
14     parser = OptionParser.new do |myparser|
15       myparser.banner = "Usage: #{$0} [opts]"
16       myparser.separator "Specific options:"
17       myparser.on("-w WIDTH", "--width",
18               "The maximum width of the enum identifier.") do |a|
19         opts.width = a.to_i
20       end
21     end
22
23     parser.parse!(args)
24     return opts
25   end
26 end
27
28 ##################### FUNCTIONS ##################### 
29 ##################### CODE ##################### 
30 $opts = MyOptionParse.parse(ARGV)
31 #pp opts
32
33 STDIN.each_line do |line|
34   line.chomp!
35   if line =~ /\#define[ \t]([^ \t]*)[ \t][ \t]*([^ \t]*)/ then
36     ident  = $1
37     val = $2
38     ident2 = "#{ident} = "
39     printf("  %-#{$opts.width}s %s,\n", ident2, val)
40   else
41     puts line
42   end
43 end