#!/usr/bin/env ruby

text_exts = %w[
  pas
  dpr
]

def run(src)
  tmp = src + '~'
  File.rename src, tmp
  open(tmp, 'r'){|i|
  open(src, 'w'){|o|
    while i.gets
      gsub!(/\bSTR2CSTR\b/, 'dl_String')
      o.print
    end
  }}
end

Dir.glob('**/*'){|entry|
  pos = entry.rindex('.')
  next if pos.nil?
  ext = entry[pos+1..-1]
  if text_exts.include? ext
    $stderr.print "run #{entry}\n"
    run entry
  end
}
