summaryrefslogtreecommitdiff
path: root/scripts/context
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2005-07-20 00:00:00 +0200
committerHans Hagen <pragma@wxs.nl>2005-07-20 00:00:00 +0200
commite1e7a447633cde21cb8ef83878a8a2aac841d1ec (patch)
tree3fad67a494cf13189fb0c0ce467307d63feb77aa /scripts/context
parentc7f924443bf5e21f5cd9210fc76c633a3a77e20e (diff)
downloadcontext-e1e7a447633cde21cb8ef83878a8a2aac841d1ec.tar.gz
stable 2005.07.20
Diffstat (limited to 'scripts/context')
-rw-r--r--scripts/context/ruby/base/kpse.rb167
-rw-r--r--scripts/context/ruby/base/tex.rb53
-rw-r--r--scripts/context/ruby/ctxtools.rb2
-rw-r--r--scripts/context/ruby/newtexexec.rb5
4 files changed, 112 insertions, 115 deletions
diff --git a/scripts/context/ruby/base/kpse.rb b/scripts/context/ruby/base/kpse.rb
index a5e2ecac2..bfd2baa30 100644
--- a/scripts/context/ruby/base/kpse.rb
+++ b/scripts/context/ruby/base/kpse.rb
@@ -9,10 +9,14 @@
# www : www.pragma-ade.com
# rename this one to environment
+#
+# todo: web2c vs miktex module and include in kpse
require 'rbconfig'
# beware $engine is lowercase in kpse
+#
+# miktex has mem|fmt|base paths
module Kpse
@@ -28,21 +32,7 @@ module Kpse
@@crossover = true
@@mswindows = Config::CONFIG['host_os'] =~ /mswin/
- # check first in bin path
-
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
- @@distribution = 'miktex' if path =~ /miktex/o
- end
-
- # if @@crossover then
- # ENV.keys.each do |k|
- # case k
- # when /\_CTX\_KPSE\_V\_(.*?)\_/io then @@located[$1] = ENV[k].dup
- # when /\_CTX\_KPSE\_P\_(.*?)\_/io then @@paths [$1] = ENV[k].dup.split(';')
- # when /\_CTX\_KPSE\_S\_(.*?)\_/io then @@scripts[$1] = ENV[k].dup
- # end
- # end
- # end
+ @@distribution = 'miktex' if ENV['PATH'] =~ /miktex[\\\/]bin/o
if @@crossover then
ENV.keys.each do |k|
@@ -54,16 +44,24 @@ module Kpse
end
end
+ def Kpse.distribution
+ @@distribution
+ end
+
+ def Kpse.miktex?
+ @@distribution == 'miktex'
+ end
+
+ def Kpse.web2c?
+ @@distribution == 'web2c'
+ end
+
def Kpse.inspect
@@located.keys.sort.each do |k| puts("located : #{k} -> #{@@located[k]}\n") end
@@paths .keys.sort.each do |k| puts("paths : #{k} -> #{@@paths [k]}\n") end
@@scripts.keys.sort.each do |k| puts("scripts : #{k} -> #{@@scripts[k]}\n") end
end
- def Kpse.distribution
- @@distribution
- end
-
def Kpse.found(filename, progname=nil, format=nil)
begin
tag = Kpse.key(filename) # all
@@ -145,97 +143,78 @@ module Kpse
# todo: miktex
- unless @@paths.key?(engine) then
- # savedengine = ENV['engine']
- if ENV['TEXFORMATS'] && ! ENV['TEXFORMATS'].empty? then
- # make sure that we have a lowercase entry
- ENV['TEXFORMATS'] = ENV['TEXFORMATS'].sub(/\$engine/io,"\$engine")
- # well, we will append anyway, so we could also strip it
- # ENV['TEXFORMATS'] = ENV['TEXFORMATS'].sub(/\$engine/io,"")
- end
- # use modern method
- if enginepath then
- formatpath = run("--engine=#{engine} --show-path=fmt")
- else
- # ENV['engine'] = engine if engine
- formatpath = run("--show-path=fmt")
- end
- # use ancient method
- if formatpath.empty? then
+ if miktex? then
+ return '.'
+ else
+ unless @@paths.key?(engine) then
+ # savedengine = ENV['engine']
+ if ENV['TEXFORMATS'] && ! ENV['TEXFORMATS'].empty? then
+ # make sure that we have a lowercase entry
+ ENV['TEXFORMATS'] = ENV['TEXFORMATS'].sub(/\$engine/io,"\$engine")
+ # well, we will append anyway, so we could also strip it
+ # ENV['TEXFORMATS'] = ENV['TEXFORMATS'].sub(/\$engine/io,"")
+ end
+ # use modern method
if enginepath then
- if @@mswindows then
- formatpath = run("--engine=#{engine} --expand-path=\$TEXFORMATS")
- else
- formatpath = run("--engine=#{engine} --expand-path=\\\$TEXFORMATS")
- end
+ formatpath = run("--engine=#{engine} --show-path=fmt")
+ else
+ # ENV['engine'] = engine if engine
+ formatpath = run("--show-path=fmt")
end
- # either no enginepath or failed run
+ # use ancient method
if formatpath.empty? then
- if @@mswindows then
- formatpath = run("--expand-path=\$TEXFORMATS")
- else
- formatpath = run("--expand-path=\\\$TEXFORMATS")
+ if enginepath then
+ if @@mswindows then
+ formatpath = run("--engine=#{engine} --expand-path=\$TEXFORMATS")
+ else
+ formatpath = run("--engine=#{engine} --expand-path=\\\$TEXFORMATS")
+ end
+ end
+ # either no enginepath or failed run
+ if formatpath.empty? then
+ if @@mswindows then
+ formatpath = run("--expand-path=\$TEXFORMATS")
+ else
+ formatpath = run("--expand-path=\\\$TEXFORMATS")
+ end
end
end
- end
- # locate writable path
- if ! formatpath.empty? then
- formatpath.split(File::PATH_SEPARATOR).each do |fp|
- fp.gsub!(/\\/,'/')
- # remove funny patterns
- fp.sub!(/^!!/,'')
- fp.sub!(/\/+$/,'')
- fp.sub!(/unsetengine/,if enginepath then engine else '' end)
- if ! fp.empty? && (fp != '.') then
- # strip (possible engine) and test for writeability
- fpp = fp.sub(/#{engine}\/*$/,'')
- if FileTest.directory?(fpp) && FileTest.writable?(fpp) then
- # use this path
- formatpath = fp.dup
- break
+ # locate writable path
+ if ! formatpath.empty? then
+ formatpath.split(File::PATH_SEPARATOR).each do |fp|
+ fp.gsub!(/\\/,'/')
+ # remove funny patterns
+ fp.sub!(/^!!/,'')
+ fp.sub!(/\/+$/,'')
+ fp.sub!(/unsetengine/,if enginepath then engine else '' end)
+ if ! fp.empty? && (fp != '.') then
+ # strip (possible engine) and test for writeability
+ fpp = fp.sub(/#{engine}\/*$/,'')
+ if FileTest.directory?(fpp) && FileTest.writable?(fpp) then
+ # use this path
+ formatpath = fp.dup
+ break
+ end
end
end
end
+ # fall back to current path
+ formatpath = '.' if formatpath.empty? || ! FileTest.writable?(formatpath)
+ # append engine but prevent duplicates
+ formatpath = File.join(formatpath.sub(/\/*#{engine}\/*$/,''), engine) if enginepath
+ begin File.makedirs(formatpath) ; rescue ; end ;
+ setpath(engine,formatpath)
+ # ENV['engine'] = savedengine
end
- # fall back to current path
- formatpath = '.' if formatpath.empty? || ! FileTest.writable?(formatpath)
- # append engine but prevent duplicates
- formatpath = File.join(formatpath.sub(/\/*#{engine}\/*$/,''), engine) if enginepath
- begin File.makedirs(formatpath) ; rescue ; end ;
- setpath(engine,formatpath)
- # ENV['engine'] = savedengine
+ return @@paths[engine].first
end
- return @@paths[engine].first
end
def Kpse.update
- case @@distribution
- when 'miktex' then
- system('initexmf --update-fndb')
- else
- # always mktexlsr anyway
-
- end
+ system('initexmf -u') if Kpse.miktex?
system('mktexlsr')
end
- def Kpse.distribution
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
- if path =~ /miktex/ then
- return 'miktex'
- end
- end
- return 'web2c'
- end
-
- def Kpse.miktex?
- distribution == 'miktex'
- end
-
- def Kpse.web2c?
- distribution == 'web2c'
- end
-
# engine support is either broken of not implemented in some
# distributions, so we need to take care of it ourselves (without
# delays due to kpse calls); there can be many paths in the string
diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb
index baa70d749..8ff7d682f 100644
--- a/scripts/context/ruby/base/tex.rb
+++ b/scripts/context/ruby/base/tex.rb
@@ -409,8 +409,20 @@ class TEX
end
end
- def iniflag() "--ini" end
- def tcxflag() "--translate-file=natural.tcx" end
+ def iniflag() # should go to kpse and kpse should become texenv
+ if Kpse.miktex? then
+ "-initialize"
+ else
+ "--ini"
+ end
+ end
+ def tcxflag(file="natural.tcx")
+ if Kpse.miktex? then
+ "-tcx=#{file}"
+ else
+ "--translate-file=#{file}"
+ end
+ end
def filestate(file)
File.mtime(file).strftime("%d/%m/%Y %H:%M:%S")
@@ -655,7 +667,7 @@ class TEX
]
def scantexpreamble(filename)
- if tex = File.open(filename) then
+ if FileTest.file?(filename) and tex = File.open(filename) then
while str = tex.gets.chomp do
if str =~ /^\%\s*(.*)/o then
vars = Hash.new
@@ -675,7 +687,7 @@ class TEX
end
def scantexcontent(filename)
- if tex = File.open(filename) then
+ if FileTest.file?(filename) and tex = File.open(filename) then
while str = tex.gets do
case str.chomp
when /^\%/o then
@@ -719,12 +731,12 @@ class TEX
fname = File.unsuffixed(filename)
rname = File.unsuffixed(resultname)
if ! rname.empty? && (rname != fname) then
- report("outputfile #{result}")
+ report("outputfile #{rname}")
['tuo','log','dvi','pdf'].each do |s|
File.silentrename(File.suffixed(fname,s),File.suffixed('texexec',s))
end
['tuo'].each do |s|
- File.silentrename(File.suffixed(rname,s),File.suffixed(fname,s)) if FileTest(suffixed(rname,s))
+ File.silentrename(File.suffixed(rname,s),File.suffixed(fname,s)) if FileTest.file?(File.suffixed(rname,s))
end
end
end
@@ -1048,16 +1060,20 @@ class TEX
return false
end
- def runtexutil(filename=[], options=['--ref','--ij','--high'])
- begin
- filename.each do |fname|
- logger = Logger.new('TeXUtil')
- if tu = TeXUtil::Converter.new(logger) and tu.loaded(fname) then
- tu.saved if tu.processed
+ def runtexutil(filename=[], options=['--ref','--ij','--high'], old=false)
+ filename.each do |fname|
+ if old then
+ Kpse.runscript('texutil',fname,options)
+ else
+ begin
+ logger = Logger.new('TeXUtil')
+ if tu = TeXUtil::Converter.new(logger) and tu.loaded(fname) then
+ tu.saved if tu.processed
+ end
+ rescue
+ Kpse.runscript('texutil',fname,options)
end
end
- rescue
- Kpse.runscript('texutil',filename,options)
end
end
@@ -1131,8 +1147,9 @@ class TEX
suffix = getvariable('suffix')
result = getvariable('result')
- runonce = getvariable('once')
- finalrun = getvariable('final') || (getvariable('arrange') && ! getvariable('noarrange'))
+ runonce = getvariable('once')
+ finalrun = getvariable('final') || (getvariable('arrange') && ! getvariable('noarrange'))
+ globalfile = getvariable('globalfile')
if getvariable('autopath') then
jobname = File.basename(jobname)
@@ -1167,9 +1184,9 @@ class TEX
jobsuffix = makestubfile(jobname,jobsuffix,forcexml) if dummyfile || forcexml
- if getvariable('globalfile') || FileTest.file?(File.suffixed(jobname,jobsuffix)) then
+ if globalfile || FileTest.file?(File.suffixed(jobname,jobsuffix)) then
- unless dummyfile # we don't need this for xml
+ if not dummyfile and not globalfile then
scantexpreamble(File.suffixed(jobname,jobsuffix))
scantexcontent(File.suffixed(jobname,jobsuffix)) if getvariable('texformats').standard?
end
diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb
index c89b1a30b..d55f27065 100644
--- a/scripts/context/ruby/ctxtools.rb
+++ b/scripts/context/ruby/ctxtools.rb
@@ -457,7 +457,7 @@ class Commands
end
- def purgeall
+ def purgeallfiles
purgefiles(true) # for old times sake
end
diff --git a/scripts/context/ruby/newtexexec.rb b/scripts/context/ruby/newtexexec.rb
index 0d9602312..9d9c880bd 100644
--- a/scripts/context/ruby/newtexexec.rb
+++ b/scripts/context/ruby/newtexexec.rb
@@ -137,7 +137,7 @@ class Commands
files = @commandline.arguments.sort
if files.length > 0 then
if f = File.open(job.tempfilename('tex'),'w') then
- job.runtexutil(files,"--figures")
+ job.runtexutil(files,"--figures", true)
figures = @commandline.checkedoption('method', 'a').downcase
paperoffset = @commandline.checkedoption('paperoffset', '0pt')
backspace = @commandline.checkedoption('backspace', '1.5cm')
@@ -193,7 +193,8 @@ class Commands
fnames.each do |ffname|
if msuffixes.include?(File.splitname(ffname)[1]) && FileTest.file?(ffname) then
if mod = File.open(job.tempfilename('tex'),'w') then
- job.runtexutil(ffname,"--documents")
+ # will become a call to ctxtools
+ job.runtexutil(ffname,"--documents", true)
if ted = File.silentopen(File.suffixed(ffname,'ted')) then
firstline = ted.gets
if firstline =~ /interface=/o then