[dev-context] libkpathsea in ruby?

Patrick Gundlach patrick at gundla.ch
Tue Dec 7 00:47:17 CET 2004


Hi,


[...]

>> (PS: anybody interested in a kpathsea.rb as an interface for libkpathsea?)

my implementation is currently using the commandline tool kpsewhich
for finding files, but confirms to the c-api in its interface:

    kp=Kpathsea.new
    kp.find_file("cont-sys.tex")
    kp.find_file("hacker.jpg","tex")

(returns nil or location of file)

it will support 

    kp.open(file,fmt)

in the future that returns an File instance. I will bind this to the
libkpathsea c library eventually.

(sorry for being so minimalistic)



# kpathsea.rb - libkpathsea access for ruby

# Last Change: Mon Dec  6 19:51:36 2004

class Kpathsea
  def initialize (progname=$0)
    raise ArgumentError if progname.match(/('|")/)
    @progname=$0
  end
  def find_file(name,fmt="tex",mustexist=false)
    raise ArgumentError if name.match(/('|")/)
    runkpsewhich(name,fmt,mustexist)
  end

  private

  def runkpsewhich(name,fmt,mustexist)
    # mustexist ignored for now
    cmdline="kpsewhich -progname=" + @progname + " -format " + fmt + " " + name
    lines = ""
    IO.popen(cmdline) do |io|
      lines = io.readlines
    end
    return $? == 0 ? lines.to_s.chomp : nil
  end
end


Patrick
-- 
ConTeXt wiki: http://contextgarden.net


More information about the dev-context mailing list