summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/perl/texutil.pl32
-rw-r--r--scripts/context/ruby/ctxtools.rb408
-rw-r--r--scripts/context/ruby/xmpl/switch.rb7
3 files changed, 430 insertions, 17 deletions
diff --git a/scripts/context/perl/texutil.pl b/scripts/context/perl/texutil.pl
index 0d80b3a98..240c52a0d 100644
--- a/scripts/context/perl/texutil.pl
+++ b/scripts/context/perl/texutil.pl
@@ -14,6 +14,10 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $
#C therefore copyrighted by \PRAGMA. See licen-en.pdf for
#C details.
+# much functionality will move to ctxtools, xmltools and pdftools; that way texutil
+# becomes limited to tui processing only, which is cleaner (also for taco's binary
+# version)
+
# Thanks to Tobias Burnus for the german translations.
# Thanks to Thomas Esser for hooking it into web2c
# Thanks to Taco Hoekwater for making the file -w proof and some fixes
@@ -1654,6 +1658,11 @@ sub HandleReferences
else
{ NormalHandleReferences } }
+# moved to ctxtools
+#
+# sub HandleDocuments
+# { my $files = @ARGV.join(' ') ; system("ctxtools $files") }
+
#D \extras
#D {documents}
#D
@@ -1719,6 +1728,7 @@ sub HandleDocuments
$SkipLevel = 0 ;
$InDocument = 0 ;
$InDefinition = 0 ;
+ $skippingbang = 0 ;
if ($ProcessType eq "")
{ $FileType=lc $FileSuffix }
else
@@ -2673,6 +2683,15 @@ sub HandleLogFile
{ Report ( "NOfUnknown", "$NOfUnknown") } } }
#D Undocumented feature.
+#
+# obsolete, i.e now in ctxtools, so this will become:
+#
+# sub PurgeFiles {
+# if ($PurgeAllFiles) {
+# system("ctxtools --purge $ARGV[0]") ;
+# } else {
+# system("ctxtools --purge --all $ARGV[0]") ;
+# }
my $removedfiles = 0 ;
my $keptfiles = 0 ;
@@ -2768,6 +2787,11 @@ sub PurgeFiles # no my in foreach
print " reclaimed bytes : $reclaimedbytes\n" }
#D Another undocumented feature.
+#
+# obsolete, i.e now in pdftools, so this will become:
+#
+# sub AnalyzeFile
+# { system("pdftools --analyze $ARGV[0]") }
sub AnalyzeFile
{ my $filename = $ARGV[0] ;
@@ -2798,10 +2822,16 @@ sub AnalyzeFile
print " links : $Link ($Named named / $Script scripts / $Cross files)\n" ;
print " widgets : $Widget\n" }
+# moved to ctxtools
+#
+# sub FilterPages
+# { system("ctxtools $ARGV{0]") }
+
sub FilterPages # temp feature / no reporting
{ my $filename = $ARGV[0] ;
return unless -f "$filename.pdf" ;
- $old = '' ; $num = 0 ;
+ my $old = '' ;
+ my $n = 0 ;
if (open(PDF,"<$filename.pdf") && open(TUO,">>$filename.tuo"))
{ binmode PDF ;
while (<PDF>)
diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb
index 65ace2f36..3e9d02e9c 100644
--- a/scripts/context/ruby/ctxtools.rb
+++ b/scripts/context/ruby/ctxtools.rb
@@ -2,7 +2,7 @@
# program : ctxtools
# copyright : PRAGMA Advanced Document Engineering
-# version : 1.0 - 2002/2004
+# version : 1.2.0 - 2002/2005
# author : Hans Hagen
# This script will harbor some handy manipulations on context
@@ -10,7 +10,7 @@
# todo: move scite here
-banner = ['CtxTools', 'version 1.1.0', '2004/2005', 'PRAGMA ADE/POD']
+banner = ['CtxTools', 'version 1.2.0', '2004/2005', 'PRAGMA ADE/POD']
unless defined? ownpath
ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'')
@@ -26,12 +26,12 @@ class String
def i_translate(element, attribute, category)
self.gsub!(/(<#{element}.*?#{attribute}=)([\"\'])(.*?)\2/) do
if category.key?($3) then
-puts "#{element} #{$3} -> #{category[$3]}\n" if element == 'cd:inherit'
-puts "#{element} #{$3} => #{category[$3]}\n" if element == 'cd:command'
+ puts "#{element} #{$3} -> #{category[$3]}\n" if element == 'cd:inherit'
+ puts "#{element} #{$3} => #{category[$3]}\n" if element == 'cd:command'
"#{$1}#{$2}#{category[$3]}#{$2}"
else
-puts "#{element} #{$3} -> ?\n" if element == 'cd:inherit'
-puts "#{element} #{$3} => ?\n" if element == 'cd:command'
+ puts "#{element} #{$3} -> ?\n" if element == 'cd:inherit'
+ puts "#{element} #{$3} => ?\n" if element == 'cd:command'
"#{$1}#{$2}#{$3}#{$2}" # unchanged
end
end
@@ -49,6 +49,8 @@ class Commands
include CommandBase
+ public
+
def touchcontextfile
dowithcontextfile(1)
end
@@ -135,6 +137,14 @@ class Commands
end
+end
+
+class Commands
+
+ include CommandBase
+
+ public
+
def jeditinterface
editinterface('jedit')
end
@@ -151,6 +161,8 @@ class Commands
editinterface('raw')
end
+ private
+
def editinterface(type='raw')
return unless FileTest.file?("cont-en.xml")
@@ -239,6 +251,14 @@ class Commands
end
+end
+
+class Commands
+
+ include CommandBase
+
+ public
+
def translateinterface
# since we know what kind of file we're dealing with,
@@ -336,23 +356,381 @@ class Commands
end
+class Commands
+
+ include CommandBase
+
+ public
+
+ def purgefiles
+
+ pattern = @commandline.arguments
+ purgeall = @commandline.option("all")
+
+ $dontaskprefixes.push(Dir.glob("mpx-*"))
+ $dontaskprefixes.flatten!
+ $dontaskprefixes.sort!
+
+ if purgeall then
+ forsuresuffixes.push(texnonesuffixes)
+ texnonesuffixes = []
+ end
+
+ if ! pattern || pattern.empty? then
+ globbed = "*.*"
+ files = Dir.glob(globbed)
+ report("purging files : #{globbed}")
+ else
+ pattern.each do |pat|
+ globbed = "#{pat}-*.*"
+ files = Dir.glob(globbed)
+ globbed = "#{pat}.*"
+ files.push(Dir.glob(globbed))
+ end
+ report("purging files : #{pattern.join(' ')}")
+ end
+ files.flatten!
+ files.sort!
+
+ $dontaskprefixes.each do |file|
+ removecontextfile(file) if FileTest.file?(file)
+ end
+ $dontasksuffixes.each do |file|
+ removecontextfile(file) if FileTest.file?(file)
+ end
+ $dontasksuffixes.each do |suffix|
+ files.each do |file|
+ removecontextfile(file) if file =~ /#{suffix}$/i
+ end
+ end
+ $forsuresuffixes.each do |suffix|
+ files.each do |file|
+ removecontextfile(file) if file =~ /\.#{suffix}$/i
+ end
+ end
+ files.each do |file|
+ if file =~ /(.*?)\.\d+$/o then
+ basename = $1
+ if file =~ /mp(graph|run)/o || FileTest.file?("#{basename}.mp") then
+ removecontextfile($file)
+ end
+ end
+ end
+ $texnonesuffixes.each do |suffix|
+ files.each do |file|
+ if file =~ /(.*)\.#{suffix}$/i then
+ if FileTest.file?("#{$1}.tex") || FileTest.file?("#{$1}.xml") || FileTest.file?("#{$1}.fo") then
+ keepcontextfile(file)
+ else
+ strippedname = $1.gsub(/\-[a-z]$/io, '')
+ if FileTest.file?("#{strippedname}.tex") || FileTest.file?("#{strippedname}.xml") then
+ keepcontextfile("#{file} (potential result file)")
+ else
+ removecontextfile(file)
+ end
+ end
+ end
+ end
+ end
+
+ if $removedfiles || $keptfiles || $persistentfiles then
+ report("removed files : #{$removedfiles}")
+ report("kept files : #{$keptfiles}")
+ report("persistent files : #{$persistentfiles}")
+ report("reclaimed bytes : #{$reclaimedbytes}")
+ end
+
+ end
+
+ private
+
+ $removedfiles = 0
+ $keptfiles = 0
+ $persistentfiles = 0
+ $reclaimedbytes = 0
+
+ $dontaskprefixes = [
+ # "tex-form.tex", "tex-edit.tex", "tex-temp.tex",
+ "texexec.tex", "texexec.tui", "texexec.tuo",
+ "texexec.ps", "texexec.pdf", "texexec.dvi",
+ "cont-opt.tex", "cont-opt.bak"
+ ]
+ $dontasksuffixes = [
+ "mpgraph.mp", "mpgraph.mpd", "mpgraph.mpo", "mpgraph.mpy",
+ "mprun.mp", "mprun.mpd", "mprun.mpo", "mprun.mpy",
+ "xlscript.xsl"
+ ]
+ $forsuresuffixes = [
+ "tui", "tup", "ted", "tes", "top",
+ "log", "tmp", "run", "bck", "rlg",
+ "mpt", "mpx", "mpd", "mpo"
+ ]
+ $texonlysuffixes = [
+ "dvi", "ps", "pdf"
+ ]
+ $texnonesuffixes = [
+ "tuo", "tub", "top"
+ ]
+
+ def removecontextfile (filename)
+ if filename && FileTest.file?(filename) then
+ begin
+ filesize = FileTest.size(filename)
+ File.delete(filename)
+ rescue
+ report("problematic : #{filename}")
+ else
+ if FileTest.file?(filename) then
+ $persistentfiles += 1
+ report("persistent : #{filename}")
+ else
+ $removedfiles += 1
+ $reclaimedbytes += filesize
+ report("removed : #{filename}")
+ end
+ end
+ end
+ end
+
+ def keepcontextfile (filename)
+ if filename && FileTest.file?(filename) then
+ $keptfiles += 1
+ report("not removed : #{filename}")
+ end
+ end
+
+end
+
+#D Documentation can be woven into a source file. The next
+#D routine generates a new, \TEX\ ready file with the
+#D documentation and source fragments properly tagged. The
+#D documentation is included as comment:
+#D
+#D \starttypen
+#D %D ...... some kind of documentation
+#D %M ...... macros needed for documenation
+#D %S B begin skipping
+#D %S E end skipping
+#D \stoptypen
+#D
+#D The most important tag is \type {%D}. Both \TEX\ and \METAPOST\
+#D files use \type{%} as a comment chacacter, while \PERL, \RUBY\
+#D and alike use \type{#}. Therefore \type{#D} is also handled.
+#D
+#D The generated file gets the suffix \type{ted} and is
+#D structured as:
+#D
+#D \starttypen
+#D \startmodule[type=suffix]
+#D \startdocumentation
+#D \stopdocumentation
+#D \startdefinition
+#D \stopdefinition
+#D \stopmodule
+#D \stoptypen
+#D
+#D Macro definitions specific to the documentation are not
+#D surrounded by start||stop commands. The suffix specifaction
+#D can be overruled at runtime, but defaults to the file
+#D extension. This specification can be used for language
+#D depended verbatim typesetting.
+
+class Commands
+
+ include CommandBase
+
+ public
+
+ def documentation
+ files = @commandline.arguments
+ processtype = @commandline.option("type")
+ files.each do |fullname|
+ if fullname =~ /(.*)\.(.+?)$/o then
+ filename, filesuffix = $1, $2
+ else
+ filename, filesuffix = fullname, 'tex'
+ end
+ filesuffix = 'tex' if filesuffix.empty?
+ fullname, resultname = "#{filename}.#{filesuffix}", "#{filename}.ted"
+ if ! FileTest.file?(fullname)
+ report("empty input file #{fullname}")
+ elsif ! tex = File.open(fullname)
+ report("invalid input file #{fullname}")
+ elsif ! ted = File.open(resultname,'w') then
+ report("unable to openresult file #{resultname}")
+ else
+ report("input file : #{fullname}")
+ report("output file : #{resultname}")
+ nofdocuments, nofdefinitions, nofskips = 0, 0, 0
+ skiplevel, indocument, indefinition, skippingbang = 0, false, false, false
+ if processtype.empty? then
+ filetype = filesuffix.downcase
+ else
+ filetype = processtype.downcase
+ end
+ report("filetype : #{filetype}")
+ # we need to signal to texexec what interface to use
+ firstline = tex.gets
+ if firstline =~ /^\%.*interface\=/ then
+ ted.puts(firstline)
+ else
+ tex.rewind # seek(0)
+ end
+ ted.puts("\\startmodule[type=#{filetype}]\n")
+ while str = tex.gets do
+ if skippingbang then
+ skippingbang = false
+ else
+ str.chomp!
+ str.sub!(/\s*$/o, '')
+ case str
+ when /^[%\#]D/io then
+ if skiplevel == 0 then
+ someline = if str.length < 3 then "" else str[3,str.length-1] end
+ if indocument then
+ ted.puts("#{someline}\n")
+ else
+ if indefinition then
+ ted.puts("\\stopdefinition\n")
+ indefinition = false
+ end
+ unless indocument then
+ ted.puts("\n\\startdocumentation\n")
+ end
+ ted.puts("#{someline}\n")
+ indocument = true
+ nofdocuments += 1
+ end
+ end
+ when /^[%\#]M/io then
+ if skiplevel == 0 then
+ someline = if str.length < 3 then "" else str[3,str.length-1] end
+ ted.puts("#{someline}\n")
+ end
+ when /^[%\%]S B/io then
+ skiplevel += 1
+ nofskips += 1
+ when /^[%\%]S E/io then
+ skiplevel -= 1
+ when /^[%\#]/io then
+ #nothing
+ when /^eval \'\(exit \$\?0\)\' \&\& eval \'exec perl/o then
+ skippingbang = true
+ else
+ if skiplevel == 0 then
+ inlocaldocument = indocument
+ someline = str
+ if indocument then
+ ted.puts("\\stopdocumentation\n")
+ indocument = false
+ end
+ if someline.empty? && indefinition then
+ ted.puts("\\stopdefinition\n")
+ indefinition = false
+ elsif indefinition then
+ ted.puts("#{someline}\n")
+ elsif ! someline.empty? then
+ ted.puts("\n\\startdefinition\n")
+ indefinition = true
+ unless inlocaldocument then
+ nofdefinitions += 1
+ ted.puts("#{someline}\n")
+ end
+ end
+ end
+ end
+ end
+ end
+ if indocument then
+ ted.puts("\\stopdocumentation\n")
+ end
+ if indefinition then
+ ted.puts("\\stopdefinition\n")
+ end
+ ted.puts("\\stopmodule\n")
+ ted.close
+
+ if nofdocuments == 0 && nofdefinitions == 0 then
+ begin
+ File.delete(resultname)
+ rescue
+ end
+ end
+ report("documentation sections : #{nofdocuments}")
+ report("definition sections : #{nofdefinitions}")
+ report("skipped sections : #{nofskips}")
+ end
+ end
+ end
+
+end
+
+#D This feature was needed when \PDFTEX\ could not yet access page object
+#D numbers (versions prior to 1.11).
+
+class Commands
+
+ include CommandBase
+
+ public
+
+ def filterpages # temp feature / no reporting
+ filename = @commandline.argument('first')
+ filename.sub!(/\.([a-z]+?)$/io,'')
+ pdffile = "#{filename}.pdf"
+ tuofile = "#{filename}.tuo"
+ if FileTest.file?(pdffile) then
+ prevline, n = '', 0
+ if (pdf = File.open(pdffile)) && (tuo = File.open(tuofile,'a')) then
+ report('filtering page object numbers')
+ pdf.binmode
+ while line = pdf.gets do
+ line.chomp
+ # typical pdftex search
+ if (line =~ /\/Type \/Page/o) && (prevline =~ /^(\d+)\s+0\s+obj/o) then
+ p = $1
+ n += 1
+ tuo.puts("\\objectreference{PDFP}{#{n}}{#{p}}{#{n}}\n")
+ else
+ prevline = line
+ end
+ end
+ end
+ pdf.close
+ tuo.close
+ report("number of pages : #{n}")
+ end
+ end
+
+end
+
logger = EXA::ExaLogger.new(banner.shift)
commandline = CommandLine.new
-commandline.registeraction('touchcontextfile', '')
-commandline.registeraction('contextversion', '')
-commandline.registeraction('translateinterface', '')
-commandline.registeraction('jeditinterface', '')
-commandline.registeraction('bbeditinterface', '')
-commandline.registeraction('sciteinterface', '')
-commandline.registeraction('rawinterface', '')
+commandline.registeraction('touchcontextfile', 'update context version')
+commandline.registeraction('contextversion', 'report context version')
+
+commandline.registeraction('jeditinterface', 'generate jedit syntax files [--pipe]')
+commandline.registeraction('bbeditinterface', 'generate bbedit syntax files [--pipe]')
+commandline.registeraction('sciteinterface', 'generate scite syntax files [--pipe]')
+commandline.registeraction('rawinterface', 'generate raw syntax files [--pipe]')
+
+commandline.registeraction('translateinterface', 'generate interface files (xml) [nl de ..]')
+commandline.registeraction('purgefiles', 'remove temporary files [--all] [basename]')
+
+commandline.registeraction('documentation', 'generate documentation file [--type=] [filename]')
+
+commandline.registeraction('filterpages') # no help, hidden temporary feature
commandline.registeraction('help')
commandline.registeraction('version')
-commandline.registerflag('recurse')
-commandline.registerflag('force')
+commandline.registervalue('type','')
+
+# commandline.registerflag('recurse')
+# commandline.registerflag('force')
commandline.registerflag('pipe')
+commandline.registerflag('all')
commandline.expand
diff --git a/scripts/context/ruby/xmpl/switch.rb b/scripts/context/ruby/xmpl/switch.rb
index 54acc19af..36cc8c346 100644
--- a/scripts/context/ruby/xmpl/switch.rb
+++ b/scripts/context/ruby/xmpl/switch.rb
@@ -78,7 +78,11 @@ module CommandBase
def help
version # is nilled when already given
@commandline.helpkeys.each do |k|
- report("#{('--'+k).ljust(@commandline.helplength+2)} #{@commandline.helptext(k)}") if @commandline.help?(k)
+ if @commandline.help?(k) then
+ message = @commandline.helptext(k)
+ message = '' if message == CommandLine::NOHELP
+ report("#{('--'+k).ljust(@commandline.helplength+2)} #{message}")
+ end
end
end
@@ -153,6 +157,7 @@ end
class CommandLine
VALUE, FLAG = 1, 2
+ NOHELP = 'no arguments'
def initialize(prefix='-')