#!/usr/bin/ruby

begin
  joinee = ARGV.shift
  dt = []
  File.foreach(File.join(__dir__, "externs.h")) do |line|
    line.gsub!(/\b(extern|static)\b/, "")
    line.strip!
    m = line.match(/\s(?<name>\w+)\s*(\[.*?\])?;/)
    if m then
      name = m["name"]
      if joinee then
        dt.push(name)
      else
        puts(name)
      end
    end
  end
  if joinee then
    printf('%s', dt.join(joinee))
  end
end
