# findbin.rb
#
# Copyright (c) 2001 Adam Spiers <adam@spiers.net>. All rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Ruby itself.
#
# Based on ideas from Perl's FindBin.

require 'abspath'

module FindBin

  if $0 == '-e' || $0 == '-'
    script = realscript = $0
    bin    = realbin    = File.expand_path(Dir.getwd)
  else
    path = $0

    # Make path absolute in case we chdir
    path = Dir.getwd + '/' + path unless path =~ %r!^/!

    script = File.basename path
    bin    = File.expand_path(File.dirname path)
    realpath = File.abs_path path

    realbin    = File.dirname  realpath
    realscript = File.basename realpath
  end

  # constantify
  Script     = script
  Bin        = bin
  RealScript = realscript
  RealBin    = realbin
  RealPath   = realpath

end

