diff options
author | Hans Hagen <pragma@wxs.nl> | 2006-07-24 10:49:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2006-07-24 10:49:00 +0200 |
commit | 72646ab6a6f3cd139beecd0407480b03ab49ff10 (patch) | |
tree | b7e979566c0aeda535d7a2f0c8e8cfa6bf51b2df /scripts | |
parent | 4bcfa86615a3095169831cf25639faa89b34468f (diff) | |
download | context-72646ab6a6f3cd139beecd0407480b03ab49ff10.tar.gz |
stable 2006.07.24 10:49
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/perl/texshow.pl | 14 | ||||
-rw-r--r-- | scripts/context/ruby/base/file.rb | 10 | ||||
-rw-r--r-- | scripts/context/ruby/base/mp.rb | 4 | ||||
-rw-r--r-- | scripts/context/ruby/base/tex.rb | 89 | ||||
-rw-r--r-- | scripts/context/ruby/ctxtools.rb | 6 | ||||
-rw-r--r-- | scripts/context/ruby/www/admin.rb | 2 | ||||
-rw-r--r-- | scripts/context/ruby/wwwserver.rb | 15 | ||||
-rw-r--r-- | scripts/context/ruby/wwwwatch.rb | 46 | ||||
-rw-r--r-- | scripts/context/ruby/xmltools.rb | 2 |
9 files changed, 130 insertions, 58 deletions
diff --git a/scripts/context/perl/texshow.pl b/scripts/context/perl/texshow.pl index 79222c9f0..772d4db84 100644 --- a/scripts/context/perl/texshow.pl +++ b/scripts/context/perl/texshow.pl @@ -3,7 +3,7 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec perl -w - #D \module #D [ file=texshow.pl, -#D version=2005.01.06, +#D version=2006.07.19, #D title=TeXShow, #D subtitle=showing \CONTEXT\ commands, #D author=Taco Hoekwater, @@ -23,6 +23,11 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec perl -w - #D one to be used. #D #D Hans Hagen - Januari 2005 +#D +#D ChangeLog: +#D \startitemize +#D \item Add keyboard bindings for quitting the app: Ctrl-q,Ctrl-x,Alt-F4 (2006/07/19) +#D \stopitemize use strict; use Getopt::Long ; @@ -63,7 +68,7 @@ my %crosslinks; print "\n"; -show('TeXShow-XML 0.2 beta','Taco Hoekwater 2004',"/"); +show('TeXShow-XML 0.21 beta','Taco Hoekwater 2006',"/"); print "\n"; @@ -220,6 +225,11 @@ sub initialize_display { $mainwindow -> bind ( "<BackSpace>", sub { delete_request() } ) ; $mainwindow -> bind ( "<Prior>", sub { prev_command() } ) ; $mainwindow -> bind ( "<Next>", sub { next_command() } ) ; + $mainwindow -> bind ( "<Control-x>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Control-X>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Control-q>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Control-Q>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Alt-F4>", sub { exit(0) } ) ; } sub show { diff --git a/scripts/context/ruby/base/file.rb b/scripts/context/ruby/base/file.rb index 42fb346c4..39bb7d467 100644 --- a/scripts/context/ruby/base/file.rb +++ b/scripts/context/ruby/base/file.rb @@ -105,12 +105,13 @@ class File end def File.silentdelete(filename) - begin File.delete(filename) ; rescue ; end + File.delete(filename) rescue false end def File.silentcopy(oldname,newname) return if File.expand_path(oldname) == File.expand_path(newname) - begin File.copy(oldname,newname) ; rescue ; end + File.makedirs(File.dirname(newname)) rescue false + File.copy(oldname,newname) rescue false end def File.silentrename(oldname,newname) @@ -118,11 +119,12 @@ class File # maybe working over multiple file systems or # apps may have mildly locked files (like gs does) return if File.expand_path(oldname) == File.expand_path(newname) - begin File.delete(newname) ; rescue ; end + File.delete(newname) rescue false begin File.rename(oldname,newname) rescue - begin File.copy(oldname,newname) ; rescue ; end + File.makedirs(File.dirname(newname)) rescue false + File.copy(oldname,newname) rescue false end end diff --git a/scripts/context/ruby/base/mp.rb b/scripts/context/ruby/base/mp.rb index d26882456..b30be1110 100644 --- a/scripts/context/ruby/base/mp.rb +++ b/scripts/context/ruby/base/mp.rb @@ -12,6 +12,7 @@ module MPTools @@definitions, @@start, @@stop, @@before, @@after = Hash.new, Hash.new, Hash.new, Hash.new, Hash.new + @@definitions['plain'] = <<EOT \\gdef\\mpxshipout{\\shipout\\hbox\\bgroup \\setbox0=\\hbox\\bgroup} @@ -34,6 +35,8 @@ EOT @@definitions['context'] = <<EOT \\ifx\\startMPXpage\\undefined + \\ifx\\loadallfontmapfiles\\undefined \\let\\loadallfontmapfiles\\relax \\fi + \\gdef\\startMPXpage {\\shipout\\hbox \\bgroup @@ -56,6 +59,7 @@ EOT \\egroup \\ht0=0pt \\dp0=0pt + \\loadallfontmapfiles \\box0 \\egroup} diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb index 29e0de44f..04dc4541a 100644 --- a/scripts/context/ruby/base/tex.rb +++ b/scripts/context/ruby/base/tex.rb @@ -319,11 +319,14 @@ class TEX begin Dir.glob("#{@@temprunfile}*").each do |name| if File.file?(name) && (File.splitname(name)[1] !~ /(pdf|dvi)/o) then - begin File.delete(name) ; rescue ; end + File.delete(name) rescue false end end rescue end + ['mpgraph.mp'].each do |file| + (File.delete(file) if (FileTest.size?(file) rescue 10) < 10) rescue false + end end def backends() @@backends.keys.sort end @@ -389,18 +392,24 @@ class TEX if str.class == String then str.split(',') else str.flatten end end - def validtexformat(str) validsomething(str,@@texformats) end - def validmpsformat(str) validsomething(str,@@mpsformats) end - def validtexengine(str) validsomething(str,@@texengines) end - def validmpsengine(str) validsomething(str,@@mpsengines) end + def validtexformat(str) validsomething(str,@@texformats,'tex') end + def validmpsformat(str) validsomething(str,@@mpsformats,'mp' ) end + def validtexengine(str) validsomething(str,@@texengines,'pdfetex') end + def validmpsengine(str) validsomething(str,@@mpsengines,'mpost' ) end def validtexmethod(str) [validsomething(str,@@texmethods)].flatten.first end def validmpsmethod(str) [validsomething(str,@@mpsmethods)].flatten.first end - def validsomething(str,something) + def validsomething(str,something,type=nil) if str then list = [str].flatten.collect do |s| - something[s] + if something[s] then + something[s] + elsif type && s =~ /\.#{type}$/ then + s + else + nil + end end .compact.uniq if list.length>0 then if str.class == String then list.first else list end @@ -538,6 +547,9 @@ class TEX # save current path savedpath = Dir.getwd # generate tex formats + unless texformats || mpsformats then + report('provide valid format (name.tex, name.mp, ...) or format id (metafun, en, nl, ...)') + end if texformats && texengine && (progname = validprogname(getvariable('progname'),texengine)) then report("using tex engine #{texengine}") texformatpath = if getvariable('local') then '.' else Kpse.formatpath(texengine,true) end @@ -1004,11 +1016,36 @@ class TEX reportruntime end + private + + def load_map_files(filename) # tui basename + # c \usedmapfile{=}{lm-texnansi} + begin + str = "" + IO.read(filename).scan(/^c\s+\\usedmapfile\{(.*?)\}\{(.*?)\}\s*$/o) do + str << "\\loadmapfile[#{$2}.map]\n" + end + rescue + return "" + else + return str + end + end + + public + def processmpgraphic getarrayvariable('files').each do |filename| setvariable('filename',filename) report("processing graphic '#{filename}'") - runtexmp(filename) + runtexmp(filename,'',false) # no purge + mapspecs = load_map_files(File.suffixed(filename,'temp','tui')) + unless getvariable('keep') then + # not enough: purge_mpx_files(filename) + Dir.glob(File.suffixed(filename,'temp*','*')).each do |fname| + File.delete(fname) unless File.basename(filename) == File.basename(fname) + end + end begin data = IO.read(File.suffixed(filename,'log')) basename = filename.sub(/\.mp$/, '') @@ -1038,6 +1075,7 @@ class TEX File.open("texexec.tex",'w') do |f| f << "\\setupoutput[pdftex]\n" f << "\\setupcolors[state=start]\n" + f << mapspecs f << "\\starttext\n" list.each do |number| f << "\\startTEXpage\n" @@ -1058,9 +1096,12 @@ class TEX File.open("texexec.tex",'w') do |f| f << "\\setupoutput[pdftex]\n" f << "\\setupcolors[state=start]\n" - f << "\\starttext \\startTEXpage\n" + f << mapspecs + f << "\\starttext\n" + f << "\\startTEXpage\n" f << "\\convertMPtoPDF{#{fullname}}{1}{1}" - f << "\\stopTEXpage \\stoptext\n" + f << "\\stopTEXpage\n" + f << "\\stoptext\n" end report("converting graphic '#{fullname}'") runtex("texexec.tex") @@ -1089,7 +1130,7 @@ class TEX getarrayvariable('files').each do |filename| setvariable('filename',filename) report("processing text of graphic '#{filename}'") - processmpx(filename,false,true) + processmpx(filename,false,true,true) end reportruntime end @@ -1353,18 +1394,18 @@ class TEX end end - def runtexmp(filename,filetype='') + def runtexmp(filename,filetype='',purge=true) checktestversion mpname = File.suffixed(filename,filetype,'mp') if File.atleast?(mpname,25) then # first run needed File.silentdelete(File.suffixed(mpname,'mpt')) - doruntexmp(mpname) + doruntexmp(mpname,nil,true,purge) mpgraphics = checkmpgraphics(mpname) mplabels = checkmplabels(mpname) if mpgraphics || mplabels then # second run needed - doruntexmp(mpname,mplabels) + doruntexmp(mpname,mplabels,true,purge) else # no labels end @@ -1445,7 +1486,7 @@ class TEX report("fixing backend map path for #{backend}") if getvariable('verbose') ENV['backend'] = backend ; ENV['progname'] = backend unless validtexengine(backend) - ENV['TEXFONTMAPS'] = ['.',"\$TEXMF/fonts/map/{#{backend},pdftex,dvips,}//"].join_path + ENV['TEXFONTMAPS'] = ['.',"\$TEXMF/fonts/map/{#{backend},pdftex,dvips,}//",'./fonts//'].join_path else report("unable to fix backend map path") if getvariable('verbose') end @@ -1720,7 +1761,7 @@ class TEX # into beginfig/endfig. We could as well do this in metafun itself. Maybe some # day ... (it may cost a bit of string space but that is cheap nowadays). - def doruntexmp(mpname,mergebe=nil,context=true) + def doruntexmp(mpname,mergebe=nil,context=true,purge=true) texfound = false mpname = File.suffixed(mpname,'mp') mpcopy = File.suffixed(mpname,'mp.copy') @@ -1752,7 +1793,7 @@ class TEX mp << "\n" mp.close end - processmpx(mpname,true) if texfound + processmpx(mpname,true,true,purge) if texfound if getvariable('batchmode') then options = ' --interaction=batch' elsif getvariable('nonstopmode') then @@ -1779,7 +1820,7 @@ class TEX # todo: use internal mptotext function and/or turn all btex/etex into textexts - def processmpx(mpname,force=false,context=true) + def processmpx(mpname,force=false,context=true,purge=true) unless force then mpname = File.suffixed(mpname,'mp') if File.atleast?(mpname,10) && (data = File.silentread(mpname)) then @@ -1828,9 +1869,7 @@ class TEX command = "dvitomp #{mpdvi} #{mpmpx}" report(command) if getvariable('verbose') ok = ok && FileTest.file?(mpdvi) && system(command) - [mptex,mpdvi,mplog].each do |mpfil| - File.silentdelete(mpfil) - end + purge_mpx_files(mpname) if purge end rescue # error in processing mpx file @@ -1838,6 +1877,14 @@ class TEX end end + def purge_mpx_files(mpname) + unless getvariable('keep') then + ['tex', 'log', 'tui', 'tuo', 'top'].each do |suffix| + File.silentdelete(File.suffixed(mpname,'temp',suffix)) + end + end + end + def checkmpgraphics(mpname) mpoptions = '' if getvariable('makempy') then diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb index 420145db0..d04688890 100644 --- a/scripts/context/ruby/ctxtools.rb +++ b/scripts/context/ruby/ctxtools.rb @@ -476,6 +476,9 @@ class Commands end end end + $dummyfiles.each do |file| + (File.delete(file) if (FileTest.size?(file) rescue 10) < 10) rescue false + end $texnonesuffixes.each do |suffix| files.each do |file| if file =~ /(.*)\.#{suffix}$/i then @@ -540,6 +543,9 @@ class Commands $texnonesuffixes = [ "tuo", "tub", "top" ] + $dummyfiles = [ + "mpgraph" + ] def removecontextfile (filename) if filename && FileTest.file?(filename) then diff --git a/scripts/context/ruby/www/admin.rb b/scripts/context/ruby/www/admin.rb index 4e85fd830..8983ca2b7 100644 --- a/scripts/context/ruby/www/admin.rb +++ b/scripts/context/ruby/www/admin.rb @@ -30,7 +30,7 @@ class WWW message('Status', "option '#{option}' not permitted #{options.inspect}") end else - message('Status', "unknown task '#{task}") + message('Status', "unknown task '#{task}'") end end diff --git a/scripts/context/ruby/wwwserver.rb b/scripts/context/ruby/wwwserver.rb index aa6352183..18ea57df1 100644 --- a/scripts/context/ruby/wwwserver.rb +++ b/scripts/context/ruby/wwwserver.rb @@ -110,13 +110,14 @@ class Server # begin @httpd = WEBrick::HTTPServer.new( - :DocumentRoot => @document_root, - :DirectoryIndex => ['index.html','index.htm','showcase.pdf'], - :Port => @port_number.to_i, - :Logger => WEBrick::Log.new(@logfile, WEBrick::Log::INFO), # DEBUG - :RequestTimeout => @request_timeout, - :MaxClients => @n_of_clients, - :AccessLog => [ + :DocumentRoot => @document_root, + :DocumentRootOptions => { :FancyIndexing => false }, + :DirectoryIndex => ['index.html','index.htm','showcase.pdf'], + :Port => @port_number.to_i, + :Logger => WEBrick::Log.new(@logfile, WEBrick::Log::INFO), # DEBUG + :RequestTimeout => @request_timeout, + :MaxClients => @n_of_clients, + :AccessLog => [ [ @accfile, WEBrick::AccessLog::COMMON_LOG_FORMAT ], [ @accfile, WEBrick::AccessLog::REFERER_LOG_FORMAT ], [ @accfile, WEBrick::AccessLog::AGENT_LOG_FORMAT ], diff --git a/scripts/context/ruby/wwwwatch.rb b/scripts/context/ruby/wwwwatch.rb index e6cb7a050..0afb9a392 100644 --- a/scripts/context/ruby/wwwwatch.rb +++ b/scripts/context/ruby/wwwwatch.rb @@ -29,7 +29,7 @@ class Watch < Monitor @@session_begin = 'begin exa session' @@session_end = 'end exa session' - attr_accessor :root_path, :work_path, :cache_path, :delay, :max_threads, :max_age, :verbose + attr_accessor :root_path, :work_path, :create, :cache_path, :delay, :max_threads, :max_age, :verbose def initialize(logger) # we need to register all @vars here becase of the monitor @threads = Hash.new @@ -46,15 +46,15 @@ class Watch < Monitor @logger = logger @verbose = false @create = false - [:INT, :TERM, :EXIT].each do |signal| - trap(signal) do - kill - exit - end - end - at_exit do - kill - end + # [:INT, :TERM, :EXIT].each do |signal| + # trap(signal) do + # kill + # exit # rescue false + # end + # end + # at_exit do + # kill + # end end def trace @@ -96,7 +96,8 @@ class Watch < Monitor end end unless File.writable?(@work_path) then - puts "no valid work path: #{@work_path}" ; exit + puts "no valid work path: #{@work_path}" + exit! rescue false # no checking, no at_exit done end unless File.writable?(@cache_path) then puts "no valid work path: #{@work_path}" ; # no reason to exit @@ -443,18 +444,19 @@ class Commands private def setup - watch = Watch.new(logger) - watch.root_path = @commandline.option('root') - watch.work_path = @commandline.option('work') - watch.cache_path = @commandline.option('cache') - watch.create = @commandline.option('create') - watch.verbose = @commandline.option('verbose') - begin - watch.max_threads = @commandline.option('threads').to_i - rescue - watch.max_threads = 5 + if watch = Watch.new(logger) then + watch.root_path = @commandline.option('root') + watch.work_path = @commandline.option('work') + watch.cache_path = @commandline.option('cache') + watch.create = @commandline.option('create') + watch.verbose = @commandline.option('verbose') + begin + watch.max_threads = @commandline.option('threads').to_i + rescue + watch.max_threads = 5 + end + watch.setup end - watch.setup return watch end diff --git a/scripts/context/ruby/xmltools.rb b/scripts/context/ruby/xmltools.rb index 8974fff23..a10d34314 100644 --- a/scripts/context/ruby/xmltools.rb +++ b/scripts/context/ruby/xmltools.rb @@ -173,7 +173,7 @@ class Commands if FileTest.file?(file+'.xml') then style = "--arg=\"style=#{style}\"" unless style.empty? modes = "--mode=#{modes}" unless modes.empty? - if system("texmfstart texexec.pl --batch --pdf --once --result=#{long} --use=mmlpag #{style} #{modes} #{file}.xml") then + if system("texmfstart texexec --batch --pdf --once --result=#{long} --use=mmlpag #{style} #{modes} #{file}.xml") then if eps then if f = open("#{file}-mmlpages.txt") then while line = f.gets do |