From 6a7298b122f57742589e973a971543eb925618eb Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Wed, 20 Oct 2010 13:35:32 -0700 Subject: [PATCH] Add define-to-enum.rb script --- define-to-enum.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) create mode 100755 define-to-enum.rb diff --git a/define-to-enum.rb b/define-to-enum.rb new file mode 100755 index 0000000..6e1e0df --- /dev/null +++ b/define-to-enum.rb @@ -0,0 +1,43 @@ +#!/usr/bin/ruby -w + +require 'optparse' +require 'ostruct' +require 'pp' + +##################### CLASSES ##################### +class MyOptionParse + def self.parse(args) + # default values + opts = OpenStruct.new + opts.width = 70 + + parser = OptionParser.new do |myparser| + myparser.banner = "Usage: #{$0} [opts]" + myparser.separator "Specific options:" + myparser.on("-w WIDTH", "--width", + "The maximum width of the enum identifier.") do |a| + opts.width = a.to_i + end + end + + parser.parse!(args) + return opts + end +end + +##################### FUNCTIONS ##################### +##################### CODE ##################### +$opts = MyOptionParse.parse(ARGV) +#pp opts + +STDIN.each_line do |line| + line.chomp! + if line =~ /\#define[ \t]([^ \t]*)[ \t][ \t]*([^ \t]*)/ then + ident = $1 + val = $2 + ident2 = "#{ident} = " + printf(" %-#{$opts.width}s %s,\n", ident2, val) + else + puts line + end +end -- 1.6.6.rc1.39.g9a42