# Extract Constants from the WebSphere MQ header files class GenerateConst # Extract Constants from Header files def GenerateConst.extract_const(filename, const_prefix, start_exp=nil, end_exp=nil) @constants = [] active = if start_exp then false else true end # Sure there is a better way File.open(filename) do |file| file.each do |line| line.rstrip! if line.length > 0 # Skip empty lines if active break if start_exp && line.match(end_exp) # Skip Comment lines, then check for a match if (line !~ /^\s*\/\*/) && (match = /\s*#define\s+(#{const_prefix}\w+)[\(\s]+([-\\\w\dx\'\"\s]+)/.match(line)) @constants << [match[1], match[2]] end else next unless line.match(start_exp) active = true end end end end @constants end # Extract MQ Constants from Header files def GenerateConst.rb_const(filename, const_prefix, exclude_exp=nil) str = '' GenerateConst.extract_const(filename, const_prefix).each do |item| const, val = item next if const.include?('_STRUC_ID') next if exclude_exp && const.match(exclude_exp) if val.include?('"') || val.include?("'") if match = val.match(/(\w+)/) val = "'#{match[0]}'" else val = "''" end end str << " %-30s = #{val}\n" % const end str end def GenerateConst.config(filename, prefix) str = "# WMQ::QueueManager execute commands\n" str << "execute_commands:\n" GenerateConst.extract_const(filename,prefix).each do |item| name = item[0].gsub(prefix,'').downcase str << " :%-26s " % "#{name}:" match = name.match(/\w+?_([\w_]+)/) str << ":#{match[1]}" if match str << "\n" end str end def GenerateConst.wmq_const(path) str = <