class PKCS11::ConstantParser

Constants

ConstGroups
ConstTemplate

Attributes

options[RW]

Public Class Methods

run(argv) click to toggle source
# File ext/generate_constants.rb, line 12
def self.run(argv)
  s = self.new
  options = Struct.new(:verbose, :const, :files).new
  OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options] <header-file.h>*"

    opts.on("-v", "--[no-]verbose", "Run verbosely", &options.method(:verbose=))
    opts.on("--const FILE", "Write const implementations to this file", &options.method(:const=))
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end.parse!(argv)
  options.files = argv
  s.options = options
  s.start!
end

Public Instance Methods

start!() click to toggle source
# File ext/generate_constants.rb, line 38
def start!
  File.open(options.const, "w") do |fd_const|
    options.files.each do |file_h|
      c_src = IO.read(file_h)
      ConstGroups.each do |const_group|
        c_src.scan(const_group.regexp) do
          const_name, const_value = $1, $2
          
          fd_const.puts "#{const_group.def}(#{const_name}); /* #{const_value} */"
        end
      end
    end
  end
end