module CGI::QueryExtension

def read_from_cmdline

offline mode. read name=value pairs on standard input.
def read_from_cmdline
  require "shellwords"
  string = unless ARGV.empty?
    ARGV.join(' ')
  else
    if STDIN.tty?
      STDERR.print(
        %|(offline mode: enter name=value pairs on standard input)\n|
      )
    end
    array = readlines rescue nil
    if not array.nil?
        array.join(' ').gsub(/\n/n, '')
    else
        ""
    end
  end.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')
  words = Shellwords.shellwords(string)
  if words.find{|x| /=/n.match(x) }
    words.join('&')
  else
    words.join('+')
  end
end