diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2006-12-21 10:20:09 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2006-12-21 10:20:09 +0000 |
commit | aebfda3e4d62174d4102d4252e843e17943fa1d9 (patch) | |
tree | a46610957f26bf5f43d0db360672ed2bccb695e5 /Master/texmf-dist/scripts/context | |
parent | 5a3b44c1e19a288c511ed1cf56d8f485f252407f (diff) |
context release 2006.12.20
git-svn-id: svn://tug.org/texlive/trunk@2835 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context')
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl | 24 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/texfont.pl | 2 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/base/ctx.rb | 18 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/base/kpsetrees.rb | 65 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/base/tex.rb | 16 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/ruby/kpseclient.rb | 42 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/context/ruby/kpseserver.rb | 7 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/mtxtools.rb | 426 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/pdftools.rb | 22 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/pstopdf.rb | 8 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/texmfstart.rb | 21 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/xmltools.rb | 120 |
12 files changed, 740 insertions, 31 deletions
diff --git a/Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl b/Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl index 08c1de5d778..6ac4f70c51e 100644 --- a/Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl +++ b/Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl @@ -61,7 +61,7 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ #D \stopuseMPgraphic #D #D \placefigure -#D [here][fig:cropcrap] +#D [here][fig:pdftrimwhite] #D {Crops and offsets.} #D {\useMPgraphic{original}} #D @@ -72,40 +72,40 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ #D The script is executed as follows: #D #D \starttyping -#D cropcrap <original> [<result>] [<switches>] +#D pdftrimwhite <original> [<result>] [<switches>] #D \stoptyping #D #D The next call crops \type {test.pdf} to its natural #D boundingbox. #D #D \starttyping -#D cropcrap test +#D pdftrimwhite test #D \stoptyping #D #D If the file has some crap at the bottom, you can say: #D #D \starttyping -#D cropcrap test --bottomcrop=2cm +#D pdftrimwhite test --bottomcrop=2cm #D \stoptyping #D #D This clips 2cm from the bottom. You can clip on all sides #D individually, in combination or at once, like in: #D #D \starttyping -#D cropcrap test --bottomcrop=2cm --crop=1cm +#D pdftrimwhite test --bottomcrop=2cm --crop=1cm #D \stoptyping #D #D The final result is a tightly cropped image. In order to get #D a 5mm margin around this image, you can say: #D #D \starttyping -#D cropcrap test --bottomcrop=2cm --offset=5mm +#D pdftrimwhite test --bottomcrop=2cm --offset=5mm #D \stoptyping #D #D By default, the script intercepts logging messages and #D writes them to a logfile with the same name as the #D resulting image and the prefix \type {log}. If no name is -#D given, the name \type {cropcrap} is used for all resulting +#D given, the name \type {pdftrimwhite} is used for all resulting #D files. #D #D By default, \CONTEXT\ is used. When installed properly, you @@ -114,14 +114,14 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ #D is valid: #D #D \starttyping -#D cropcrap test result --bot=2cm --off=5mm --plain +#D pdftrimwhite test result --bot=2cm --off=5mm --plain #D \stoptyping #D #D The current implementation uses an intermediate \POSTSCRIPT\ #D file. This may change as \GHOSTSCRIPT\ gets more clever with #D \PDF\ files. #D -#D In \in {figure} [fig:cropcrap] the green rectangle is the +#D In \in {figure} [fig:pdftrimwhite] the green rectangle is the #D picture we want to keep. Around this picture, we want a #D margin, represented by the black rectangle, and specified by #D \type {--offset}. The white rectangle is the cropbox @@ -175,14 +175,14 @@ my $gs = "gs" ; my $thisisunix = $Config{'osname'} !~ /dos|mswin/i ; -#D When no resulting file is given, we use \type {cropcrap} +#D When no resulting file is given, we use \type {pdftrimwhite} #D as name (checked later). my $figurefile = "" ; my $resultfile = "" ; my $tempfile = "" ; -my $programname = "cropcrap" ; +my $programname = "pdftrimwhite" ; #D Messages are temporarily saved and written to a log file #D afterwards. @@ -227,7 +227,7 @@ my $width = my $height = my $llx = my $lly = my $urx = my $ury = 0 ; sub PrintHelp { print "This is PdfTrimWhite\n\n" . "usage:\n\n" . - "cropcrap [switches] filename result\n\n" . + "pdftrimwhite [switches] filename result\n\n" . "switches:\n\n" . "--crop=<dimen>\n" . "--offset=<dimen>\n" . diff --git a/Master/texmf-dist/scripts/context/perl/texfont.pl b/Master/texmf-dist/scripts/context/perl/texfont.pl index e6ebf7029da..5b3c1f1d766 100644 --- a/Master/texmf-dist/scripts/context/perl/texfont.pl +++ b/Master/texmf-dist/scripts/context/perl/texfont.pl @@ -562,7 +562,7 @@ if ($sourcepath eq "auto") # todo uppercase root { report ("removing : $nam") ; unlink "$nam" } my $mapfile = "$encoding$varlabel-$vendor-$collection" ; - foreach my $map ("pdftex","dvips", "dvipdfm") + foreach my $map ("pdftex","dvips", "dvipdfm") { my $maproot = "$fontroot/fonts/map/$map/context/"; if (-e "$maproot$mapfile.map") { report ("renaming : $mapfile.map -> $mapfile.bak") ; diff --git a/Master/texmf-dist/scripts/context/ruby/base/ctx.rb b/Master/texmf-dist/scripts/context/ruby/base/ctx.rb index dff9570d837..4ee2715b88a 100644 --- a/Master/texmf-dist/scripts/context/ruby/base/ctx.rb +++ b/Master/texmf-dist/scripts/context/ruby/base/ctx.rb @@ -21,7 +21,7 @@ require 'rexml/document' class CtxRunner - attr_reader :environments, :modules, :filters + attr_reader :environments, :modules, :filters, :flags @@suffix = 'prep' @@ -42,6 +42,7 @@ class CtxRunner @environments = Array.new @modules = Array.new @filters = Array.new + @flags = Array.new end def manipulate(ctxname=nil,defaultname=nil) @@ -116,6 +117,18 @@ class CtxRunner variables['job'] = @jobname end root = @xmldata.root +REXML::XPath.each(root,"/ctx:job//ctx:flags/ctx:flag") do |flg| + @flags << justtext(flg) +end +REXML::XPath.each(root,"/ctx:job//ctx:resources/ctx:environment") do |sty| + @environments << justtext(sty) +end +REXML::XPath.each(root,"/ctx:job//ctx:resources/ctx:module") do |mod| + @modules << justtext(mod) +end +REXML::XPath.each(root,"/ctx:job//ctx:resources/ctx:filter") do |fil| + @filters << justtext(fil) +end begin REXML::XPath.each(root,"//ctx:block") do |blk| if @jobname && blk.attributes['pattern'] then @@ -141,6 +154,9 @@ class CtxRunner REXML::XPath.each(root,"/ctx:job//ctx:process/ctx:resources/ctx:filter") do |fil| @filters << justtext(fil) end +REXML::XPath.each(root,"/ctx:job//ctx:process/ctx:flags/ctx:flag") do |flg| + @flags << justtext(flg) +end commands = Hash.new REXML::XPath.each(root,"/ctx:job//ctx:preprocess/ctx:processors/ctx:processor") do |pre| begin diff --git a/Master/texmf-dist/scripts/context/ruby/base/kpsetrees.rb b/Master/texmf-dist/scripts/context/ruby/base/kpsetrees.rb new file mode 100644 index 00000000000..8e3fb20f854 --- /dev/null +++ b/Master/texmf-dist/scripts/context/ruby/base/kpsetrees.rb @@ -0,0 +1,65 @@ +require 'monitor' +require 'base/kpsefast' + +class KpseTrees < Monitor + + def initialize + @trees = Hash.new + @monitor = Monitor.new + end + + def choose(filenames,environment) + current = filenames.join('|') + # @monitor do + unless @trees[current] then + 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 + puts "enabling tree #{current}" + # end + current + 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 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/Master/texmf-dist/scripts/context/ruby/base/tex.rb b/Master/texmf-dist/scripts/context/ruby/base/tex.rb index 7b5bba55a25..1b526f6e56c 100644 --- a/Master/texmf-dist/scripts/context/ruby/base/tex.rb +++ b/Master/texmf-dist/scripts/context/ruby/base/tex.rb @@ -1777,8 +1777,20 @@ end end ctx.savelog(File.suffixed(rawbase,'ctl')) - envs = ctx.environments - mods = ctx.modules + envs = ctx.environments + mods = ctx.modules + flags = ctx.flags + + flags.each do |f| + f.sub!(/^\-+/,'') + if f =~ /^(.*?)=(.*)$/ then + setvariable($1,$2) + else + setvariable(f,true) + end + end + + report("using flags #{flags.join(' ')}") if flags.size > 0 # merge environment and module specs diff --git a/Master/texmf-dist/scripts/context/ruby/kpseclient.rb b/Master/texmf-dist/scripts/context/ruby/kpseclient.rb new file mode 100755 index 00000000000..547cd9feed8 --- /dev/null +++ b/Master/texmf-dist/scripts/context/ruby/kpseclient.rb @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby + +# require 'profile' + +n, t = 100, Time.now + +$: << File.dirname(File.expand_path($0)) + +require 'base/kpseremote' + +kpse = KpseRemote.new # fast start (.25 sec) +# kpse = KpseRemote::fetch # slow start (1-2 sec) + +# puts kpse.inspect + +exit unless kpse + +if true then + + n = 1 + loop do + str = kpse.find_file('texnansi.enc') + puts("#{n}: #{str}") + n += 1 + sleep(1) + end + +else + + print((Time.now-t).to_s + ' ') + n.times do |i| + str = kpse.find_file('texnansi.enc') + if i == 0 then + print(Time.now-t).to_s + ' ' + print str + else + print ' .' + end + end + puts ' ' + ((Time.now-t)/n).to_s + +end diff --git a/Master/texmf-dist/scripts/context/ruby/kpseserver.rb b/Master/texmf-dist/scripts/context/ruby/kpseserver.rb new file mode 100755 index 00000000000..b9fe2d8a6b8 --- /dev/null +++ b/Master/texmf-dist/scripts/context/ruby/kpseserver.rb @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +$: << File.dirname(File.expand_path($0)) + +require 'base/kpseremote' + +KpseRemote::start_server diff --git a/Master/texmf-dist/scripts/context/ruby/mtxtools.rb b/Master/texmf-dist/scripts/context/ruby/mtxtools.rb new file mode 100644 index 00000000000..7cbe68c0d4c --- /dev/null +++ b/Master/texmf-dist/scripts/context/ruby/mtxtools.rb @@ -0,0 +1,426 @@ +#!/usr/bin/env ruby
+
+# program : mtxtools
+# copyright : PRAGMA Advanced Document Engineering
+# version : 2004-2005
+# author : Hans Hagen
+#
+# info : j.hagen@xs4all.nl
+# www : www.pragma-ade.com
+
+# This script hosts MetaTeX related features.
+
+banner = ['MtxTools', 'version 1.0.0', '2006', 'PRAGMA ADE/POD']
+
+$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!
+
+require 'base/switch'
+require 'base/logger'
+require 'base/system'
+require 'base/kpse'
+
+class Reporter
+ def report(str)
+ puts(str)
+ end
+end
+
+module ConTeXt
+
+ def ConTeXt::banner(filename,companionname,compact=false)
+ "-- filename : #{File.basename(filename)}\n" +
+ "-- comment : companion to #{File.basename(companionname)} (in ConTeXt)\n" +
+ "-- author : Hans Hagen, PRAGMA-ADE, Hasselt NL\n" +
+ "-- copyright: PRAGMA ADE / ConTeXt Development Team\n" +
+ "-- license : see context related readme files\n" +
+ if compact then "\n-- remark : compact version\n" else "" end
+ end
+
+end
+
+class UnicodeTables
+
+ @@version = "1.001"
+
+ @@shape_a = /^((GREEK|LATIN|HEBREW)\s*(SMALL|CAPITAL|)\s*LETTER\s*[A-Z]+)$/
+ @@shape_b = /^((GREEK|LATIN|HEBREW)\s*(SMALL|CAPITAL|)\s*LETTER\s*[A-Z]+)\s*(.+)$/
+
+ @@shape_a = /^(.*\s*LETTER\s*[A-Z]+)$/
+ @@shape_b = /^(.*\s*LETTER\s*[A-Z]+)\s+WITH\s+(.+)$/
+
+ attr_accessor :context, :comment
+
+ def initialize(logger=Reporter.new)
+ @data = Array.new
+ @logger = logger
+ @error = false
+ @context = true
+ @comment = true
+ @shapes = Hash.new
+ end
+
+ def load_unicode_data(filename='unicodedata.txt')
+ # beware, the unicodedata table is bugged, sometimes ending
+ @logger.report("reading base data from #{filename}") if @logger
+ begin
+ IO.readlines(filename).each do |line|
+ if line =~ /^[0-9A-F]{4,4}/ then
+ d = line.chomp.sub(/\;$/, '').split(';')
+ if d then
+ while d.size < 15 do d << '' end
+ n = d[0].hex
+ @data[n] = d
+ if d[1] =~ @@shape_a then
+ @shapes[$1] = d[0]
+ end
+ end
+ end
+ end
+ rescue
+ @error = true
+ @logger.report("error while reading base data from #{filename}") if @logger
+ end
+ end
+
+ def load_context_data(filename='contextnames.txt')
+ @logger.report("reading data from #{filename}") if @logger
+ begin
+ IO.readlines(filename).each do |line|
+ if line =~ /^[0-9A-F]{4,4}/ then
+ d = line.chomp.split(';')
+ if d then
+ n = d[0].hex
+ if @data[n] then
+ @data[d[0].hex] << d[1] # adobename == 15
+ @data[d[0].hex] << d[2] # contextname == 16
+ else
+ @logger.report("missing information about #{d} in #{filename}") if @logger
+ end
+ end
+ end
+ end
+ rescue
+ @error = true
+ @logger.report("error while reading context data from #{filename}") if @logger
+ end
+ end
+
+ def save_metatex_data(filename='char-def.lua',compact=false)
+ if not @error then
+ begin
+ File.open(filename,'w') do |f|
+ @logger.report("saving data in #{filename}") if @logger
+ f << ConTeXt::banner(filename,'char-def.tex',compact)
+ f << "\n"
+ f << "\nif not versions then versions = { } end versions['#{filename.gsub(/\..*?$/,'')}'] = #{@@version}\n"
+ f << "\n"
+ f << "if not characters then characters = { } end\n"
+ f << "if not characters.data then characters.data = { } end\n"
+ f << "\n"
+ f << "characters.data = {\n" if compact
+ @data.each do |d|
+ if d then
+ r = metatex_data(d)
+ if compact then
+ f << "\t" << "[0x#{d[0]}]".rjust(8,' ') << " = { #{r.join(", ").gsub(/\t/,'')} }, \n"
+ else
+ f << "characters.define { -- #{d[0].hex}" << "\n"
+ f << r.join(",\n") << "\n"
+ f << "}" << "\n"
+ end
+ end
+ end
+ f << "}\n" if compact
+ end
+ rescue
+ @logger.report("error while saving data in #{filename}") if @logger
+ else
+ @logger.report("#{@data.size} (#{sprintf('%X',@data.size)}) entries saved in #{filename}") if @logger
+ end
+ else
+ @logger.report("not saving data in #{filename} due to previous error") if @logger
+ end
+ end
+
+ def metatex_data(d)
+ r = Array.new
+ r << "\tunicodeslot=0x#{d[0]}"
+ if d[2] && ! d[2].empty? then
+ r << "\tcategory='#{d[2].downcase}'"
+ end
+ if @context then
+ if d[15] && ! d[15].empty? then
+ r << "\tadobename='#{d[15]}'"
+ end
+ if d[16] && ! d[16].empty? then
+ r << "\tcontextname='#{d[16]}'"
+ end
+ end
+ if @comment then
+ if d[1] == "<control>" then
+ r << "\tdescription='#{d[10]}'" unless d[10].empty?
+ else
+ r << "\tdescription='#{d[1]}'" unless d[1].empty?
+ end
+ end
+ if d[1] =~ @@shape_b then
+ r << "\tshcode=0x#{@shapes[$1]}" if @shapes[$1]
+ end
+ if d[12] && ! d[12].empty? then
+ r << "\tuccode=0x#{d[12]}"
+ elsif d[14] && ! d[14].empty? then
+ r << "\tuccode=0x#{d[14]}"
+ end
+ if d[13] && ! d[13].empty? then
+ r << "\tlccode=0x#{d[13]}"
+ end
+ if d[5] && ! d[5].empty? then
+ special, specials = '', Array.new
+ c = d[5].split(/\s+/).collect do |cc|
+ if cc =~ /^\<(.*)\>$/io then
+ special = $1.downcase
+ else
+ specials << "0x#{cc}"
+ end
+ end
+ if specials.size > 0 then
+ special = 'char' if special.empty?
+ r << "\tspecials={'#{special}',#{specials.join(',')}}"
+ end
+ end
+ return r
+ end
+
+ def save_xetex_data(filename='enco-xtx.tex')
+ if not @error then
+ begin
+ minnumber, maxnumber, n = 0x001F, 0xFFFF, 0
+ File.open(filename,'w') do |f|
+ @logger.report("saving data in #{filename}") if @logger
+ f << "% filename : #{filename}\n"
+ f << "% comment : poor man's alternative for a proper enco file\n"
+ f << "% author : Hans Hagen, PRAGMA-ADE, Hasselt NL\n"
+ f << "% copyright: PRAGMA ADE / ConTeXt Development Team\n"
+ f << "% license : see context related readme files\n"
+ f << "\n"
+ f << "\\ifx\\setcclcuc\\undefined\n"
+ f << "\n"
+ f << " \\def\\setcclcuc #1 #2 #3 %\n"
+ f << " {\\global\\catcode\"#1=11 \n"
+ f << " \\global\\lccode \"#1=\"#2 \n"
+ f << " \\global\\uccode \"#1=\"#3 }\n"
+ f << "\n"
+ f << "\\fi\n"
+ f << "\n"
+ @data.each do |d|
+ if d then
+ number, type = d[0], d[2].downcase
+ if number.hex >= minnumber && number.hex <= maxnumber && type =~ /^l(l|u|t)$/o then
+ if d[13] && ! d[13].empty? then
+ lc = d[13]
+ else
+ lc = number
+ end
+ if d[12] && ! d[12].empty? then
+ uc = d[12]
+ elsif d[14] && ! d[14].empty? then
+ uc = d[14]
+ else
+ uc = number
+ end
+ if @comment then
+ f << "\\setcclcuc #{number} #{lc} #{uc} % #{d[1]}\n"
+ else
+ f << "\\setcclcuc #{number} #{lc} #{uc} \n"
+ end
+ n += 1
+ end
+ end
+ end
+ f << "\n"
+ f << "\\endinput\n"
+ end
+ rescue
+ @logger.report("error while saving data in #{filename}") if @logger
+ else
+ @logger.report("#{n} entries saved in #{filename}") if @logger
+ end
+ else
+ @logger.report("not saving data in #{filename} due to previous error") if @logger
+ end
+ end
+
+end
+
+class RegimeTables
+
+ @@version = "1.001"
+
+ def initialize(logger=Reporter.new)
+ @logger = logger
+ reset
+ end
+
+ def reset
+ @code, @regime, @filename, @loaded = Array.new(256), '', '', false
+ (32..127).each do |i|
+ @code[i] = [sprintf('%04X',i), i.chr]
+ end
+ end
+
+ def load(filename)
+ begin
+ reset
+ if filename =~ /regi\-(ini|run|uni|utf|syn)/ then
+ report("skipping #{filename}")
+ else
+ report("loading file #{filename}")
+ @regime, unicodeset = File.basename(filename).sub(/\..*?$/,''), false
+ IO.readlines(filename).each do |line|
+ case line
+ when /^\#/ then
+ # skip
+ when /^(0x[0-9A-F]+)\s+(0x[0-9A-F]+)\s+\#\s+(.*)$/ then
+ @code[$1.hex], unicodeset = [$2, $3], true
+ when /^(0x[0-9A-F]+)\s+(0x[0-9A-F]+)\s+/ then
+ @code[$1.hex], unicodeset = [$2, ''], true
+ end
+ end
+ reset if not unicodeset
+ end
+ rescue
+ report("problem in loading file #{filename}")
+ reset
+ else
+ if ! @regime.empty? then
+ @loaded = true
+ else
+ reset
+ end
+ end
+ end
+
+ def save(filename,compact=false)
+ begin
+ if @loaded && ! @regime.empty? then
+ if File.expand_path(filename) == File.expand_path(@filename) then
+ report("saving in #{filename} is blocked")
+ else
+ report("saving file #{filename}")
+ File.open(filename,'w') do |f|
+ f << ConTeXt::banner(filename,'regi-ini.tex',compact)
+ f << "\n"
+ f << "\nif not versions then versions = { } end versions['#{filename.gsub(/\..*?$/,'')}'] = #{@@version}\n"
+ f << "\n"
+ f << "if not regimes then regimes = { } end\n"
+ f << "if not regimes.data then regimes.data = { } end\n"
+ f << "\n"
+ if compact then
+ f << "regimes.data[\"#{@regime}\"] = { [0] = \n\t"
+ i = 17
+ @code.each_index do |c|
+ if (i-=1) == 0 then
+ i = 16
+ f << "\n\t"
+ end
+ if @code[c] then
+ f << @code[c][0].rjust(6,' ')
+ else
+ f << "0x0000".rjust(6,' ')
+ end
+ f << ', ' if c<@code.length-1
+ end
+ f << "\n}\n"
+ else
+ @code.each_index do |c|
+ if @code[c] then
+ f << someregimeslot(@regime,c,@code[c][0],@code[c][1])
+ else
+ f << someregimeslot(@regime,c,'','')
+ end
+ end
+ end
+ end
+ end
+ end
+ rescue
+ report("problem in saving file #{filename} #{$!}")
+ end
+ end
+
+ def report(str)
+ @logger.report(str)
+ end
+
+ private
+
+ def someregimeslot(regime,slot,unicodeslot,comment)
+ "regimes.define { #{if comment.empty? then '' else '-- ' end} #{comment}\n" +
+ "\tregime='#{regime}',\n" +
+ "\tslot='#{sprintf('0x%02X',slot)}',\n" +
+ "\tunicodeslot='#{if unicodeslot.empty? then '0x0000' else unicodeslot end}'\n" +
+ "}\n"
+ end
+
+ public
+
+ def RegimeTables::convert(filenames,compact=false)
+ filenames.each do |filename|
+ txtfile = File.expand_path(filename)
+ luafile = File.join(File.dirname(txtfile),'regi-'+File.basename(txtfile.sub(/\..*?$/, '.lua')))
+ unless txtfile == luafile then
+ regime = RegimeTables.new
+ regime.load(txtfile)
+ regime.save(luafile,compact)
+ end
+ end
+ end
+
+end
+
+class Commands
+
+ include CommandBase
+
+ def unicodetable
+ unicode = UnicodeTables.new(logger)
+ unicode.load_unicode_data
+ unicode.load_context_data
+ unicode.save_metatex_data('char-def.lua',@commandline.option('compact'))
+ end
+
+ def xetextable
+ unicode = UnicodeTables.new(logger)
+ unicode.load_unicode_data
+ unicode.load_context_data
+ # unicode.comment = false
+ unicode.save_xetex_data
+ end
+
+ def regimetable
+ if @commandline.arguments.length > 0 then
+ RegimeTables::convert(@commandline.arguments, @commandline.option('compact'))
+ else
+ RegimeTables::convert(Dir.glob("cp*.txt") , @commandline.option('compact'))
+ RegimeTables::convert(Dir.glob("8859*.txt") , @commandline.option('compact'))
+ end
+ end
+
+end
+
+logger = Logger.new(banner.shift)
+commandline = CommandLine.new
+
+commandline.registeraction('unicodetable', 'create unicode table for metatex/luatex')
+commandline.registeraction('regimetable', 'create regime table(s) for metatex/luatex [--compact]')
+commandline.registeraction('xetextable' , 'create unicode table for xetex')
+
+# general
+
+commandline.registeraction('help')
+commandline.registeraction('version')
+commandline.registerflag('compact')
+
+commandline.expand
+
+Commands.new(commandline,logger,banner).send(commandline.action || 'help')
diff --git a/Master/texmf-dist/scripts/context/ruby/pdftools.rb b/Master/texmf-dist/scripts/context/ruby/pdftools.rb index d40e2d85281..6dfa47374d4 100644 --- a/Master/texmf-dist/scripts/context/ruby/pdftools.rb +++ b/Master/texmf-dist/scripts/context/ruby/pdftools.rb @@ -739,13 +739,23 @@ class Commands end def countpages - filenames, n = findfiles('pdf'), 0 + if @commandline.option('pattern') then + filenames, n = globfiles(@commandline.option('pattern'),'pdf'), 0 + else + filenames, n = findfiles('pdf'), 0 + end + threshold = @commandline.option('threshold').to_i rescue 0 filenames.each do |filename| if `pdfinfo #{filename}`.chomp =~ /^pages\s*\:\s*(\d+)/mois then - report("#{$1.rjust(4)} pages found in #{filename}") - n += $1.to_i - end + p = $1 + m = p.to_i rescue 0 + if threshold == 0 or m > threshold then + report("#{p.rjust(4)} pages found in #{filename}") + n += m + end + end end + report("") report("#{n.to_s.rjust(4)} pages in total") end @@ -791,7 +801,7 @@ commandline.registeraction('colorimage', 'filename --colorspec= [--retain - commandline.registeraction('convertimage', 'filename [--retain --subpath]') commandline.registeraction('downsampleimage', 'filename [--retain --subpath --lowres --normal]') commandline.registeraction('info', 'filename') -commandline.registeraction('countpages', 'pattern') +commandline.registeraction('countpages', '[--pattern --threshold]') commandline.registeraction('analyzefile' , 'filename') @@ -801,6 +811,8 @@ commandline.registeraction('version') commandline.registervalue('colorname') commandline.registervalue('colorspec') commandline.registervalue('subpath') +commandline.registervalue('pattern') +commandline.registervalue('threshold',0) commandline.registerflag('lowres') commandline.registerflag('medres') diff --git a/Master/texmf-dist/scripts/context/ruby/pstopdf.rb b/Master/texmf-dist/scripts/context/ruby/pstopdf.rb index a677cb61788..3625f4d83dc 100644 --- a/Master/texmf-dist/scripts/context/ruby/pstopdf.rb +++ b/Master/texmf-dist/scripts/context/ruby/pstopdf.rb @@ -42,7 +42,10 @@ class Commands def main filename = @commandline.argument('first') pattern = @commandline.option('pattern') - globfiles(pattern) if filename.empty? && ! pattern.empty? + if filename.empty? && ! pattern.empty? then + pattern = "**/#{pattern}" if @commandline.option('recurse') + globfiles(pattern) + end filename = @commandline.argument('first') if filename.empty? then help @@ -343,6 +346,8 @@ class Commands elsif magick.supported?(filename) then # report("processing non ps/pdf file #{filename}") handle_magick(magick,filename) + else + report("option not supported for #{filename}") end end @@ -507,6 +512,7 @@ commandline.registervalue('outputpath') commandline.registerflag('watch') commandline.registerflag('force') +commandline.registerflag('recurse') commandline.registervalue('delay',2) diff --git a/Master/texmf-dist/scripts/context/ruby/texmfstart.rb b/Master/texmf-dist/scripts/context/ruby/texmfstart.rb index a886b2aa142..de4a18d2eb5 100644 --- a/Master/texmf-dist/scripts/context/ruby/texmfstart.rb +++ b/Master/texmf-dist/scripts/context/ruby/texmfstart.rb @@ -1429,7 +1429,7 @@ end $mswindows = Config::CONFIG['host_os'] =~ /mswin/ $separator = File::PATH_SEPARATOR -$version = "2.0.2" +$version = "2.0.3" $ownpath = File.dirname($0) if $mswindows then @@ -1804,14 +1804,16 @@ def changeddir?(path) if path.empty? then return true else + oldpath = File.expand_path(path) begin - Dir.chdir(path) if ! path.empty? + Dir.chdir(path) if not path.empty? rescue report("unable to change to directory: #{path}") else report("changed to directory: #{path}") end - return File.expand_path(Dir.getwd) == File.expand_path(path) + newpath = File.expand_path(Dir.getwd) + return oldpath == newpath end end @@ -1971,10 +1973,15 @@ def find(filename,program) end filename.sub!(/^.*[\\\/]/, '') # next we look at the current path and the callerpath - [ ['.','current'], - [$ownpath,'caller'], ["#{$ownpath}/../#{suffixlist[0]}",'caller'], - [registered("THREAD"),'thread'], ["#{registered("THREAD")}/../#{suffixlist[0]}",'thread'], - ].each do |p| + pathlist = [ ] + progpath = $applications[suffixlist[0]] + threadok = registered("THREAD") !~ /unknown/ + pathlist << ['.','current'] + pathlist << [$ownpath,'caller'] if $ownpath != '.' + pathlist << ["#{$ownpath}/../#{progpath}",'caller'] if progpath + pathlist << [registered("THREAD"),'thread'] if threadok + pathlist << ["#{registered("THREAD")}/../#{progpath}",'thread'] if progpath && threadok + pathlist.each do |p| if p && ! p.empty? && ! (p[0] == 'unknown') then suffixlist.each do |suffix| fname = "#{filename}.#{suffix}" diff --git a/Master/texmf-dist/scripts/context/ruby/xmltools.rb b/Master/texmf-dist/scripts/context/ruby/xmltools.rb index fe4fbde22ec..5b4a112b8b5 100644 --- a/Master/texmf-dist/scripts/context/ruby/xmltools.rb +++ b/Master/texmf-dist/scripts/context/ruby/xmltools.rb @@ -15,7 +15,7 @@ # This script will harbor some handy manipulations on tex # related files. -banner = ['XMLTools', 'version 1.2.0', '2002/2006', 'PRAGMA ADE/POD'] +banner = ['XMLTools', 'version 1.2.1', '2002/2006', 'PRAGMA ADE/POD'] $: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq! @@ -400,6 +400,119 @@ class Commands end end + def filter + + require "rexml/document" + + element = @commandline.option('element') + files = @commandline.arguments + result = "xmltools.xlg" + + if element.empty? then + report("provide element using --element") + elsif files.length == 0 then + report("provide filename(s)") + else + begin + File.open(result,'w') do |f| + f << "<?xml version='1.0'?>\n\n" + f << "<xlg:document>\n\n" + total = 0 + files.sort.each do |file| + begin + report("loading: #{file}") + data = REXML::Document.new(IO.read(file)) + rescue + report("error: invalid xml") + else + found = 0 + report("filtering: #{element}") + REXML::XPath.each(data,"//#{element}") do |table| + str = table.to_s + if str.length > 0 then + total += 1 + found += 1 + report("found: #{total} / #{found} / #{str.length} bytes") + f << "<xlg:file name='#{file}'>\n\n" unless found > 1 + f << "<xlg:filtered n='#{total}' m='#{found}'>" + f << "#{str.gsub(/^\s*/m,'').gsub(/\s*$/m,'')}" + f << "</xlg:filtered>\n\n" + end + end + f << "</xlg:file>\n\n" if found > 0 + end + end + f << "</xlg:document>\n" + end + report("result: #{result}") + rescue + report("error in opening #{result}") + end + end + + end + + def enhance + oldname = @commandline.argument('first') + newname = @commandline.argument('second') + verbose = @commandline.option('verbose') + # todo: options, maybe a config file + if ! newname || newname.empty? then + newname = oldname + ".prep" + end + if FileTest.file?(oldname) then + report("") if verbose + data = IO.read(oldname) + elements = Array.new + preamble = "" + done = false + data.sub!(/^(.*?)\s*(<[a-z])/mois) do + preamble = $1 + $2 + end + # hide elements + data.gsub!(/<(.*?)>/mois) do + elements << $1 + "<#{elements.length}>" + end + # abc[-/]def + data.gsub!(/([a-z]{3,})([\/\-])([a-z]{3,})/mois) do + done = true + report("compound: #{$1}#{$2}#{$3}") if verbose + "#{$1}<compound token='#{$2}'/>#{$3}" + end + # (abcd + data.gsub!(/(\()([a-z]{4,})/mois) do + done = true + report("compound: #{$1}#{$2}") if verbose + "<compound token='#{$1}'/>#{$2}" + end + # abcd) + data.gsub!(/(\()([a-z]{4,})/mois) do + done = true + report("compound: #{$1}#{$2}") if verbose + "#{$2}<compound token='#{$2}'/>" + end + # roll back elements + data.gsub!(/<(\d+)>/mois) do + "<#{elements.shift}>" + end + File.open(newname,'wb') do |f| + f << preamble + f << "\n" + f << data + end + if verbose then + if done then + report("") + report(oldname," converted to ",newname) + else + report(oldname," copied to ",newname) + end + end + end + end + def cleanup # todo, share loading/saving with previous file = @commandline.argument('first') @@ -508,6 +621,8 @@ commandline.registeraction('dir', 'generate directory listing') commandline.registeraction('mmlpages','generate graphic from mathml') commandline.registeraction('analyze', 'report entities and elements [--utf --process]') commandline.registeraction('cleanup', 'cleanup xml file [--force]') +commandline.registeraction('enhance', 'enhance xml file (partial)') +commandline.registeraction('filter', 'filter elements from xml file [element=]') # commandline.registeraction('dir', 'filename --pattern= --output= [--recurse --stripname --longname --url --root]') # commandline.registeraction('mmlpages','filename [--eps --jpg --png --style= --mode=]') @@ -520,8 +635,10 @@ commandline.registeraction('version') commandline.registerflag('stripname') commandline.registerflag('longname') commandline.registerflag('recurse') +commandline.registerflag('verbose') commandline.registervalue('pattern') +commandline.registervalue('element') commandline.registervalue('url') commandline.registervalue('output') commandline.registervalue('root') @@ -533,7 +650,6 @@ commandline.registerflag('utf') commandline.registerflag('process') commandline.registervalue('style') commandline.registervalue('modes') -commandline.registervalue('verbose') commandline.expand |