# $Id: qp.rb,v 1.4 2004/04/22 14:47:49 eto Exp $
# Copyright (C) 2003-2004 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL2.

module QP
  def caller_msg(ca)
    file, linenum, msg = ca.first.split(/:([0-9]+):/)
    msg = $1 if msg =~ /^in `(.+)'$/
    File.basename(file)+':'+linenum+':'+msg
  end
  module_function :caller_msg

  def ar_inspect(ar)
    "["+ar.map {|arg| arg.inspect }.join(', ')+"]"
  end
  module_function :ar_inspect

  def runtime()
    $__qp_t__ = Time.now if !$__qp_t__
    d = Time.now - $__qp_t__
    sprintf("%.1f", d)
  end
  module_function :runtime

  def qp(ca, *args)
    QP.caller_msg(ca)+"\t"+QP.ar_inspect(args)
  end
  module_function :qp

  def qt(ca, *args)
    QP.runtime()+":"+QP.caller_msg(ca)+"\t"+QP.ar_inspect(args)
  end
  module_function :qt
end

def qp(*args) print QP.qp(caller(1), *args)+"\n"; end
def pt(*args) print QP.qt(caller(1), *args)+"\n"; end
