class IDL::Options

def self.load_config(opt)

def self.load_config(opt)
  # first collect config from known (standard and configured) locations
  _rc_paths = [RIDLRC_GLOBAL]
  _loaded_rc_paths = []
  (ENV['RIDLRC'] || '').split(/:|;/).each do |p|
    _rc_paths << p unless _rc_paths.include?(p)
  end
  _rc_paths.collect { |path| File.expand_path(path) }.each do |rcp|
    IDL.log(3, "Testing rc path #{rcp}")
    if File.readable?(rcp) && !_loaded_rc_paths.include?(rcp)
      opt.load(rcp)
      _loaded_rc_paths << rcp
    else
      IDL.log(3, "Ignoring #{File.readable?(rcp) ? 'already loaded' : 'inaccessible'} rc path #{rcp}")
    end
  end
  # now scan working path for any rc files
  _cwd = File.expand_path(Dir.getwd)
  IDL.log(3, "scanning working path #{_cwd} for rc files")
  # first collect any rc files found
  _rc_paths = []
  begin
    _rcp = File.join(_cwd, RIDLRC)
    if File.readable?(_rcp) && !_loaded_rc_paths.include?(_rcp)
      _rc_paths << _rcp unless _rc_paths.include?(_rcp)
    else
      IDL.log(3, "Ignoring #{File.readable?(_rcp) ? 'already loaded' : 'inaccessible'} rc path #{_rcp}")
    end
    break if /\A(.:(\\|\/)|\.|\/)\Z/ =~ _cwd
    _cwd = File.dirname(_cwd)
  end while true
  # now load them in reverse order
  _rc_paths.reverse.each do |_rcp|
    opt.load(_rcp)
    _loaded_rc_paths << _rcp
  end
end