#!/usr/local/bin/ruby

=begin
  http://foo.bar.co.jp/(ۤ)
  Ȥѥ󤬤
  <a href="http://foo.bar.co.jp/">ۤ</a>
  ִ롣
=end

require 'kconv'

$euc = false
while /^-\w/ =~ ARGV[0]
  case ARGV[0]
    when /^-e$/
    $euc=true;
  end
  ARGV.shift
end
$euc = true if /euc|-e$/ =~ $0

while line=gets
  line = Kconv::toeuc(line)
  line.gsub!(%r,((https?|ftp|mailto)://[-A-z0-9_.:~+%/]+)\(([^()]+)\),,
	     "<a href=\"\\1\">\\3</a>")
  print (if $euc then line else Kconv::tojis(line) end)
end
