diff options
author | Hans Hagen <pragma@wxs.nl> | 2004-10-19 00:00:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2004-10-19 00:00:00 +0200 |
commit | fab4c585fb2e32c04b8086db8b08a3478538230c (patch) | |
tree | 43f3014d8d6b9d4adf90aedcdbdacd867f0e19ba /scripts | |
parent | 7d1c22dedd29f5cdc98b2f2dad60cd174b1945e0 (diff) | |
download | context-fab4c585fb2e32c04b8086db8b08a3478538230c.tar.gz |
stable 2004.10.19
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/perl/texexec.pl | 14 | ||||
-rw-r--r-- | scripts/context/ruby/ctxtools.rb | 96 | ||||
-rw-r--r-- | scripts/context/ruby/texmfstart.rb | 90 | ||||
-rw-r--r-- | scripts/context/ruby/textools.rb | 122 |
4 files changed, 234 insertions, 88 deletions
diff --git a/scripts/context/perl/texexec.pl b/scripts/context/perl/texexec.pl index 1693094ea..3d01f3011 100644 --- a/scripts/context/perl/texexec.pl +++ b/scripts/context/perl/texexec.pl @@ -303,6 +303,7 @@ if ($Foxet) { $ProducePdfT = 1 ; $ForceXML = 1 ; $Modules = "foxet" ; + $Purge = 1 ; } # a set file (like blabla.bat) can set paths now @@ -2178,19 +2179,22 @@ sub LocatedFormatPath { my $FormatPath = shift; my $EnginePath = shift; if ( ( $FormatPath eq '' ) && ( $kpsewhich ne '' ) ) { - $FormatPath = `$kpsewhich --show-path=fmt`; + $FormatPath = `$kpsewhich --expand-var=\$TEXFORMATS` ; chomp $FormatPath; + if ($FormatPath eq '') { + $FormatPath = `$kpsewhich --show-path=fmt`; + chomp $FormatPath; + } $FormatPath =~ s/\.+\;//o; # should be a sub $FormatPath =~ s/\;.*//o; $FormatPath =~ s/\!//go; + $FormatPath =~ s/\\/\//go; $FormatPath =~ s/\/\//\//go; - $FormatPath =~ s/\\\\/\//go; $FormatPath =~ s/[\/\\]$//; - $FormatPath .= '/'; - if ( ( $FormatPath ne '' ) && $Verbose ) { print " located formatpath : $FormatPath\n"; } + $FormatPath .= '/'; } if ($UseEnginePath && ($FormatPath ne '' && ($FormatPath !~ /$EnginePath\/$/))) { @@ -2208,7 +2212,7 @@ sub RunOneFormat { my @TeXFormatPath; my $TeXPrefix = ""; if ( ( $fmtutil ne "" ) && ( $FormatName !~ /metafun|mptopdf/io ) ) { -# could not happen, not supported any more + # could not happen, not supported any more my $cmd = "$fmtutil --byfmt $FormatName"; if ($Verbose) { print "\n$cmd\n\n" } MakeUserFile; # this works only when the path is kept diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb new file mode 100644 index 000000000..36b34f30e --- /dev/null +++ b/scripts/context/ruby/ctxtools.rb @@ -0,0 +1,96 @@ +#!/usr/bin/env ruby + +# program : ctxtools +# copyright : PRAGMA Advanced Document Engineering +# version : 1.0 - 2002/2004 +# author : Hans Hagen + +# This script will harbor some handy manipulations on context +# related files. + +banner = ['CtxTools', 'version 1.0', '2004', 'PRAGMA ADE/POD'] + +unless defined? ownpath + ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'') + $: << ownpath +end + +require 'ftools' +require 'xmpl/switch' +require 'exa/logger' + +class Commands + + include CommandBase + + def touchcontextfile + maincontextfile = 'context.tex' + unless FileTest.file?(maincontextfile) then + begin + maincontextfile = `kpsewhich -progname=context #{maincontextfile}`.chomp + rescue + maincontextfile = '' + end + end + touchfile(maincontextfile) unless maincontextfile.empty? + end + + private + + def touchfile(filename) + + if FileTest.file?(filename) then + if data = IO.read(filename) then + timestamp = Time.now.strftime('%Y.%m.%d') + prevstamp = '' + begin + data.gsub!(/\\contextversion\{(\d+\.\d+\.\d+)\}/) do + prevstamp = $1 + "\\contextversion{#{timestamp}}" + end + rescue + else + begin + File.delete(filename+'.old') + rescue + end + begin + File.copy(filename,filename+'.old') + rescue + end + begin + if f = File.open(filename,'w') then + f.puts(data) + f.close + end + rescue + end + end + if prevstamp.empty? then + report("#{filename} is not updated, no timestamp found") + else + report("#{filename} is updated from #{prevstamp} to #{timestamp}") + end + end + else + report("#{filename} is not found") + end + + end + +end + +logger = EXA::ExaLogger.new(banner.shift) +commandline = CommandLine.new + +commandline.registeraction('touchcontextfile', '') + +commandline.registeraction('help') +commandline.registeraction('version') + +commandline.registerflag('recurse') +commandline.registerflag('force') + +commandline.expand + +Commands.new(commandline,logger,banner).send(commandline.action || 'help') diff --git a/scripts/context/ruby/texmfstart.rb b/scripts/context/ruby/texmfstart.rb index 8d5175325..67aba9dbe 100644 --- a/scripts/context/ruby/texmfstart.rb +++ b/scripts/context/ruby/texmfstart.rb @@ -9,6 +9,8 @@ # info : j.hagen@xs4all.nl # www : www.pragma-pod.com / www.pragma-ade.com +# no special requirements, i.e. no exa modules/classes used + # texmfstart [switches] filename [optional arguments] # # ruby2exe texmfstart --help -> avoids stub test @@ -29,7 +31,7 @@ if $mswindows then require "Win32API" GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', ['P','P','N'], 'N') - GetLongPathName = Win32API.new('kernel32', 'GetLongPathName', ['P','P','N'], 'N') + GetLongPathName = Win32API.new('kernel32', 'GetLongPathName', ['P','P','N'], 'N') def dowith_pathname (filename,filemethod) filename.gsub!(/\\/o,'/') @@ -83,6 +85,7 @@ end $applications = Hash.new $suffixinputs = Hash.new +$predefined = Hash.new $suffixinputs['pl'] = 'PERLINPUTS' $suffixinputs['rb'] = 'RUBYINPUTS' @@ -90,6 +93,16 @@ $suffixinputs['py'] = 'PYTHONINPUTS' $suffixinputs['jar'] = 'JAVAINPUTS' $suffixinputs['pdf'] = 'PDFINPUTS' +$predefined['texexec'] = 'texexec.pl' +$predefined['texutil'] = 'texutil.pl' +$predefined['texfont'] = 'texfont.pl' +$predefined['examplex'] = 'examplex.rb' +$predefined['concheck'] = 'concheck.rb' +$predefined['textools'] = 'textools.rb' +$predefined['pdftools'] = 'pdftools.rb' +$predefined['exatools'] = 'exatools.rb' +$predefined['xmltools'] = 'xmltools.rb' + $scriptlist = 'rb|pl|py|jar' $documentlist = 'pdf|ps|eps|htm|html' @@ -131,6 +144,24 @@ def launch(filename) end end +def expanded(arg) + arg.gsub(/kpse\:(\S+)/o) do + original, resolved = $1, '' + begin + resolved = `kpsewhich -progname=#{program} -format=\"other text files\" #{file}`.chomp + rescue + resolved = '' + end + if resolved.empty? then + report("#{original} is not resolved") unless $report + original + else + report("#{original} is resolved to #{resolved}") unless $report + resolved + end + end +end + def runoneof(application,fullname,browserpermitted) if browserpermitted && launch(fullname) then return true @@ -140,28 +171,28 @@ def runoneof(application,fullname,browserpermitted) applications = $applications[application] if applications.class == Array then if $report then - print [fullname,$arguments].join(' ') + print [fullname,expanded($arguments)].join(' ') return true else applications.each do |a| - if system([a,fullname,$arguments].join(' ')) then + if system([a,fullname,expanded($arguments)].join(' ')) then return true end end end elsif applications.empty? then if $report then - print [fullname,$arguments].join(' ') + print [fullname,expanded($arguments)].join(' ') return true else - return system([fullname,$arguments].join(' ')) + return system([fullname,expanded($arguments)].join(' ')) end else if $report then - print [applications,fullname,$arguments].join(' ') + print [applications,fullname,expanded($arguments)].join(' ') return true else - return system([applications,fullname,$arguments].join(' ')) + return system([applications,fullname,expanded($arguments)].join(' ')) end end return false @@ -173,11 +204,11 @@ def report(str) end def usage - print "version : 1.04 - 2003/2004 - www.pragma-ade.com\n" + print "version : 1.05 - 2003/2004 - www.pragma-ade.com\n" print("\n") print("usage : texmfstart [switches] filename [optional arguments]\n") print("\n") - print("switches : --verbose --report --browser\n") + print("switches : --verbose --report --browser --direct\n") print(" --program --file --page --arguments\n") print(" --make --lmake --wmake\n") print("\n") @@ -186,21 +217,23 @@ def usage print(" texmfstart showcase.pdf\n") print(" texmfstart --page=2 --file=showcase.pdf\n") print(" texmfstart --program=yourtex yourscript.pl arg-1 arg-2\n") + print(" texmfstart --direct xsltproc kpse:somefile.xsl somefile.xml\n") + print(" texmfstart bin:xsltproc kpse:somefile.xsl somefile.xml\n") end # somehow registration does not work out (at least not under windows) def registered?(filename) - return ENV['texmfstart.'+filename] != nil + return ENV["texmfstart.#{filename}"] != nil end def registered(filename) - return ENV['texmfstart.'+filename] + return ENV["texmfstart.#{filename}"] end def register(filename,fullname) if fullname && ! fullname.empty? then # && FileTest.file?(fullname) - ENV['texmfstart.'+filename] = fullname + ENV["texmfstart.#{filename}"] = fullname return true else return false @@ -208,6 +241,10 @@ def register(filename,fullname) end def find(filename,program) + if $predefined.key?(filename) then + report("expanding '#{filename}' to '#{$predefined[filename]}'") + filename = $predefined[filename] + end if registered?(filename) then report("already located '#{filename}'") return registered(filename) @@ -219,7 +256,7 @@ def find(filename,program) else suffixlist = [$scriptlist.split('|'),$documentlist.split('|')].flatten end - # first we honor a given path or + # first we honor a given path if filename =~ /[\\\/]/ then report("trying to honor '#{filename}'") suffixlist.each do |suffix| @@ -392,6 +429,14 @@ def run(fullname) return false end +def direct(fullname) + begin + return system([fullname.sub(/^bin\:/, ''),expanded($arguments)].join(' ')) + rescue + return false + end +end + def make(filename,windows=false,linux=false) basename = filename.dup basename.sub!(/\.[^.]+?$/, '') @@ -408,14 +453,15 @@ def make(filename,windows=false,linux=false) program = 'texmfstart' if $indirect || ! program || program.empty? begin if windows && f = open(basename+'.bat','w') then - f.puts("@echo off\n") - f.puts("#{program} #{filename} %*\n") + f.binmode + f.write("@echo off\015\012") + f.write("#{program} #{filename} %*\015\012") f.close report("windows stub '#{basename}.bat' made") - end - if linux && f = open(basename,'w') then - f.puts("#!/bin/sh\n") - f.puts("#{program} #{filename} $@\n") + elsif linux && f = open(basename,'w') then + f.binmode + f.write("#!/bin/sh\012") + f.write("#{program} #{filename} $@\012") f.close report("unix stub '#{basename}' made") end @@ -434,6 +480,7 @@ $directives = hashed(ARGV) $help = $directives['help'] || false $filename = $directives['file'] || '' $program = $directives['program'] || 'context' +$direct = $directives['direct'] || false $page = $directives['page'] || 0 $browser = $directives['browser'] || false $report = $directives['report'] || false @@ -477,7 +524,8 @@ elsif $make then end elsif $browser && $filename =~ /^http\:\/\// then launch($filename) +elsif $direct || $filename =~ /^bin\:/ then + direct($filename) else - # run(find($filename,$program)) run(find(shortpathname($filename),$program)) -end
\ No newline at end of file +end diff --git a/scripts/context/ruby/textools.rb b/scripts/context/ruby/textools.rb index d8928099c..6c8b08813 100644 --- a/scripts/context/ruby/textools.rb +++ b/scripts/context/ruby/textools.rb @@ -352,6 +352,8 @@ class Commands def replace + report('replace file') + if newname = @commandline.argument('first') then if newname && ! newname.empty? then report @@ -462,35 +464,34 @@ class Commands return used end - def touchcontextfile - maincontextfile = 'context.tex' - unless FileTest.file?(maincontextfile) then - begin - maincontextfile = `kpsewhich -progname=context #{maincontextfile}`.chomp - rescue - maincontextfile = '' - end - end - touchfile(maincontextfile) unless maincontextfile.empty? - end - def downcasefilenames - if @commandline.option('recurse') then - files = Dir.glob('**/*') - else - files = Dir.glob('*') - end - if files && files.length>0 then + + report('downcase filenames') + + force = @commandline.option('force') + + # if @commandline.option('recurse') then + # files = Dir.glob('**/*') + # else + # files = Dir.glob('*') + # end + # if files && files.length>0 then + + if files = findfiles() then files.each do |oldname| if FileTest.file?(oldname) then newname = oldname.downcase if oldname != newname then - begin - File.rename(oldname,newname) - rescue - report("#{oldname} == #{oldname}\n") + if force then + begin + File.rename(oldname,newname) + rescue + report("#{oldname} == #{oldname}\n") + else + report("#{oldname} => #{newname}\n") + end else - report("#{oldname} => #{newname}\n") + report("(#{oldname} => #{newname})\n") end end end @@ -498,43 +499,40 @@ class Commands end end - private # specific + def stripformfeeds - def touchfile(filename) + report('strip formfeeds') - if FileTest.file?(filename) then - if data = IO.read(filename) then - timestamp = Time.now.strftime('%Y.%m.%d') - begin - data.gsub!(/\\contextversion\{(\d+)\.(\d+)\.(\d+)\}/) do - "\\contextversion{#{timestamp}}" - end - rescue - else - begin - File.delete(filename+'.old') - rescue - end + force = @commandline.option('force') + + if files = findfiles() then + files.each do |filename| + if FileTest.file?(filename) then begin - File.copy(filename,filename+'.old') + data = IO.readlines(filename).join('') rescue - end - begin - if f = File.open(filename,'w') then - f.puts(data) - f.close + else + if data.gsub!(/\n*\f\n*/io,"\n\n") then + if force then + if f = open(filename,'w') then + report("#{filename} is stripped\n") + f.puts(data) + f.close + else + report("#{filename} cannot be stripped\n") + end + else + report("#{filename} will be stripped\n") + end end - rescue end end - report("#{filename} is touched as #{timestamp}") end - else - report("#{filename} is not found") end - end + private # specific + def movefiles(from_path,to_path,suffix,&block) obsolete = 'obsolete' force = @commandline.option('force') @@ -642,19 +640,19 @@ end logger = EXA::ExaLogger.new(banner.shift) commandline = CommandLine.new -commandline.registeraction('touchcontextfile', '') # private -commandline.registeraction('downcasefilenames', '') # private - -commandline.registeraction('removemapnames' , '[pattern] [--recurse]') -commandline.registeraction('restoremapnames' , '[pattern] [--recurse]') -commandline.registeraction('hidemapnames' , '[pattern] [--recurse]') -commandline.registeraction('videmapnames' , '[pattern] [--recurse]') -commandline.registeraction('findfile' , 'filename [--recurse]') -commandline.registeraction('unzipfiles' , '[pattern] [--recurse]') -commandline.registeraction('fixafmfiles' , '[pattern] [--recurse]') -commandline.registeraction('mactodos' , '[pattern] [--recurse]') -commandline.registeraction('fixtexmftrees' , '[texmfroot] [--force]') -commandline.registeraction('replace' , 'filename [--force]') +commandline.registeraction('removemapnames' , '[pattern] [--recurse]') +commandline.registeraction('restoremapnames' , '[pattern] [--recurse]') +commandline.registeraction('hidemapnames' , '[pattern] [--recurse]') +commandline.registeraction('videmapnames' , '[pattern] [--recurse]') +commandline.registeraction('findfile' , 'filename [--recurse]') +commandline.registeraction('unzipfiles' , '[pattern] [--recurse]') +commandline.registeraction('fixafmfiles' , '[pattern] [--recurse]') +commandline.registeraction('mactodos' , '[pattern] [--recurse]') +commandline.registeraction('fixtexmftrees' , '[texmfroot] [--force]') +commandline.registeraction('replace' , 'filename [--force]') +commandline.registeraction('downcasefilenames', '[--recurse] [--force]') # not yet documented +commandline.registeraction('stripformfeeds' , '[--recurse] [--force]') # not yet documented + commandline.registeraction('help') commandline.registeraction('version') |