summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2006-04-07 11:24:00 +0200
committerHans Hagen <pragma@wxs.nl>2006-04-07 11:24:00 +0200
commit0ab7b264bf7e57960becb890b45a51caae7d920b (patch)
treebd0f2f2756bb728b480f6cdf6cfdd090af422974 /scripts
parent39a70fce9851e47de70b762fbf9d081afc30b908 (diff)
downloadcontext-0ab7b264bf7e57960becb890b45a51caae7d920b.tar.gz
stable 2006.04.07 11:24
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/ruby/base/kpse/drb.rb57
-rw-r--r--scripts/context/ruby/base/kpse/soap.rb82
-rw-r--r--scripts/context/ruby/base/kpse/trees.rb84
-rw-r--r--scripts/context/ruby/texmfstart.rb22
4 files changed, 243 insertions, 2 deletions
diff --git a/scripts/context/ruby/base/kpse/drb.rb b/scripts/context/ruby/base/kpse/drb.rb
new file mode 100644
index 000000000..db1ce0eec
--- /dev/null
+++ b/scripts/context/ruby/base/kpse/drb.rb
@@ -0,0 +1,57 @@
+require 'drb'
+require 'base/kpse/trees'
+
+class KpseServer
+
+ attr_accessor :port
+
+ def initialize(port=7000)
+ @port = port
+ end
+
+ def start
+ puts "starting drb service at port #{@port}"
+ DRb.start_service("druby://localhost:#{@port}", KpseTrees.new)
+ trap(:INT) do
+ DRb.stop_service
+ end
+ DRb.thread.join
+ end
+
+ def stop
+ # todo
+ end
+
+end
+
+class KpseClient
+
+ attr_accessor :port
+
+ def initialize(port=7000)
+ @port = port
+ @kpse = nil
+ end
+
+ def start
+ # only needed when callbacks are used / slow, due to Socket::getaddrinfo
+ # DRb.start_service
+ end
+
+ def object
+ @kpse = DRbObject.new(nil,"druby://localhost:#{@port}")
+ end
+
+end
+
+
+# SERVER_URI="druby://localhost:8787"
+#
+# # Start a local DRbServer to handle callbacks.
+# #
+# # Not necessary for this small example, but will be required
+# # as soon as we pass a non-marshallable object as an argument
+# # to a dRuby call.
+# DRb.start_service
+#
+# timeserver = DRbObject.new_with_uri(SERVER_URI)
diff --git a/scripts/context/ruby/base/kpse/soap.rb b/scripts/context/ruby/base/kpse/soap.rb
new file mode 100644
index 000000000..5ec45e954
--- /dev/null
+++ b/scripts/context/ruby/base/kpse/soap.rb
@@ -0,0 +1,82 @@
+require 'soap/rpc/standaloneServer'
+require 'soap/rpc/driver'
+
+require 'base/kpse/trees'
+
+class KpseService < SOAP::RPC::StandaloneServer
+
+ def on_init
+ kpse = KpseTrees.new
+ add_method(kpse, 'choose', 'files', 'environment')
+ add_method(kpse, 'load', 'files', 'environment')
+ add_method(kpse, 'expand_variables', 'tree')
+ add_method(kpse, 'expand_braces', 'tree', 'str')
+ add_method(kpse, 'expand_path', 'tree', 'str')
+ add_method(kpse, 'expand_var', 'tree', 'str')
+ add_method(kpse, 'show_path', 'tree', 'str')
+ add_method(kpse, 'var_value', 'tree', 'str')
+ add_method(kpse, 'find_file', 'tree', 'filename')
+ add_method(kpse, 'find_files', 'tree', 'filename', 'first')
+ end
+
+end
+
+class KpseServer
+
+ @@url = 'http://kpse.thismachine.org/KpseService'
+
+ attr_accessor :port
+
+ def initialize(port=7000)
+ @port = port
+ @server = nil
+ end
+
+ def start
+ puts "starting soap service at port #{@port}"
+ @server = KpseService.new('KpseServer', @@url, '0.0.0.0', @port.to_i)
+ trap(:INT) do
+ @server.shutdown
+ end
+ status = @server.start
+ end
+
+ def stop
+ @server.shutdown rescue false
+ end
+
+end
+
+class KpseClient
+
+ @@url = 'http://kpse.thismachine.org/KpseService'
+
+ attr_accessor :port
+
+ def initialize(port=7000)
+ @port = port
+ @kpse = nil
+ end
+
+ def start
+ @kpse = SOAP::RPC::Driver.new("http://localhost:#{port}/", @@url)
+ @kpse.add_method('choose','files', 'environment')
+ @kpse.add_method('load','files', 'environment')
+ @kpse.add_method('expand_variables', 'tree')
+ @kpse.add_method('expand_braces', 'tree', 'str')
+ @kpse.add_method('expand_path', 'tree', 'str')
+ @kpse.add_method('expand_var', 'tree', 'str')
+ @kpse.add_method('show_path', 'tree', 'str')
+ @kpse.add_method('var_value', 'tree', 'str')
+ @kpse.add_method('find_file', 'tree', 'filename')
+ @kpse.add_method('find_files', 'tree', 'filename', 'first')
+ end
+
+ def object
+ @kpse
+ end
+
+end
+
+
+
diff --git a/scripts/context/ruby/base/kpse/trees.rb b/scripts/context/ruby/base/kpse/trees.rb
new file mode 100644
index 000000000..9c872eb18
--- /dev/null
+++ b/scripts/context/ruby/base/kpse/trees.rb
@@ -0,0 +1,84 @@
+require 'monitor'
+require 'base/kpsefast'
+
+class KpseTrees < Monitor
+
+ def initialize
+ @trees = Hash.new
+ end
+
+ def pattern(filenames)
+ filenames.join('|').gsub(/\\+/o,'/').downcase
+ end
+
+ def choose(filenames,environment)
+ current = pattern(filenames)
+ load(filenames,environment) unless @trees[current]
+ puts "enabling tree #{current}"
+ current
+ end
+
+ def fetch(filenames,environment) # will send whole object !
+ current = pattern(filenames)
+ load(filenames,environment) unless @trees[current]
+ puts "fetching tree #{current}"
+ @trees[current]
+ end
+
+ def load(filenames,environment)
+ current = pattern(filenames)
+ puts "loading tree #{current}"
+ @trees[current] = KpseFast.new
+ @trees[current].push_environment(environment)
+ @trees[current].load_cnf(filenames)
+ @trees[current].expand_variables
+ @trees[current].load_lsr
+ end
+
+ def set(tree,key,value)
+ case key
+ when 'progname' then @trees[tree].progname = value
+ when 'engine' then @trees[tree].engine = value
+ when 'format' then @trees[tree].format = value
+ end
+ end
+ def get(tree,key)
+ case key
+ when 'progname' then @trees[tree].progname
+ when 'engine' then @trees[tree].engine
+ when 'format' then @trees[tree].format
+ end
+ end
+
+ def load_cnf(tree)
+ @trees[tree].load_cnf
+ end
+ def load_lsr(tree)
+ @trees[tree].load_lsr
+ end
+ def expand_variables(tree)
+ @trees[tree].expand_variables
+ end
+ def expand_braces(tree,str)
+ @trees[tree].expand_braces(str)
+ end
+ def expand_path(tree,str)
+ @trees[tree].expand_path(str)
+ end
+ def expand_var(tree,str)
+ @trees[tree].expand_var(str)
+ end
+ def show_path(tree,str)
+ @trees[tree].show_path(str)
+ end
+ def var_value(tree,str)
+ @trees[tree].var_value(str)
+ end
+ def find_file(tree,filename)
+ @trees[tree].find_file(filename)
+ end
+ def find_files(tree,filename,first)
+ @trees[tree].find_files(filename,first)
+ end
+
+end
diff --git a/scripts/context/ruby/texmfstart.rb b/scripts/context/ruby/texmfstart.rb
index 0320ce97a..72c90ad8f 100644
--- a/scripts/context/ruby/texmfstart.rb
+++ b/scripts/context/ruby/texmfstart.rb
@@ -32,12 +32,30 @@
$ownpath = File.expand_path(File.dirname($0)) unless defined? $ownpath
+# base/kpseremote
+# texmfstart-lib/base/kpseremote
+# ../../texmf-local/scripts/context/ruby
+# ../../texmf/scripts/context/ruby
+
$: << $ownpath
+$: << File.expand_path("#{$ownpath}/texmfstart-lib")
+$: << File.expand_path("#{$ownpath}/../../texmf-local/scripts/context/ruby")
+$: << File.expand_path("#{$ownpath}/../../texmf/scripts/context/ruby")
require "rbconfig"
-require 'base/kpseremote'
-require 'base/kpsedirect'
+['base/kpseremote','base/kpsedirect'].each do |basemodule|
+ begin
+ require basemodule
+ rescue Exception
+ puts("unable to locate #{basemodule} on library paths:\n\n")
+ puts($:.join("\n") + "\n")
+ puts("an option is to copy\n\n")
+ puts(" <texmf-local or texmf>/scripts/context/ruby/base\n\n")
+ puts("to e.g.\n\n")
+ puts(" <path of texmfstart script>/texmfstart-lib/base")
+ end
+end
$mswindows = Config::CONFIG['host_os'] =~ /mswin/
$separator = File::PATH_SEPARATOR