summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2005-11-16 00:00:00 +0100
committerHans Hagen <pragma@wxs.nl>2005-11-16 00:00:00 +0100
commit8a1e1ae9a3235940054faa37188c17a249d3b79a (patch)
treed44da9f48210ce7293b144a1b5363a9f405dd865 /scripts
parent840798e323e582f82ca9fba1294b9ec996d86c0d (diff)
downloadcontext-8a1e1ae9a3235940054faa37188c17a249d3b79a.tar.gz
stable 2005.11.16
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/ruby/base/state.rb2
-rw-r--r--scripts/context/ruby/base/tex.rb27
-rw-r--r--scripts/context/ruby/ctxtools.rb112
3 files changed, 125 insertions, 16 deletions
diff --git a/scripts/context/ruby/base/state.rb b/scripts/context/ruby/base/state.rb
index f57231592..4b2088128 100644
--- a/scripts/context/ruby/base/state.rb
+++ b/scripts/context/ruby/base/state.rb
@@ -56,7 +56,7 @@ class FileState
sum = ''
begin
if FileTest.file?(filename) && (data = IO.read(filename)) then
- data.gsub!(/\n.*?(#{[omit].flatten.join('|')}).*?\n/ms,"\n") if omit
+ data.gsub!(/\n.*?(#{[omit].flatten.join('|')}).*?\n/) do "\n" end if omit
sum = MD5.new(data).hexdigest.upcase
end
rescue
diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb
index 2654c4732..a8a200b72 100644
--- a/scripts/context/ruby/base/tex.rb
+++ b/scripts/context/ruby/base/tex.rb
@@ -771,7 +771,7 @@ class TEX
end
def makestubfile(rawname,forcexml=false)
- if tmp = File.open(File.suffixed(rawname,'run'),'w') then
+ if tmp = openedfile(File.suffixed(rawname,'run')) then
tmp << "\\starttext\n"
if forcexml then
if FileTest.file?(rawname) && (xml = File.open(rawname)) then
@@ -1361,13 +1361,15 @@ class TEX
mpdata.gsub!(/^\#.*\n/o,'')
File.silentrename(mpfile,mpcopy)
texfound = mergebe || mpdata =~ /btex .*? etex/o
- if mp = File.silentopen(mpfile,'w') then
+ if mp = openedfile(mpfile) then
mpdata.gsub!(/(btex.*?)\;(.*?etex)/o) do "#{$1}@@@#{$2}" end
- mpdata.gsub!(/(\".*?)\;(.*?\")/o) do "#{$1}@@@#{$2}" end
+ # mpdata.gsub!(/(\".*?)\;(.*?\")/o) do "#{$1}@@@#{$2}" end
+ mpdata.gsub!(/(\".*?\")/o) do "#{$1.gsub(/\;/o,'@@@')}" end
mpdata.gsub!(/\;/o, "\;\n")
- mpdata.gsub!(/\n+/o, "\n")
- mpdata.gsub!(/(btex.*?)@@@(.*?etex)/o) do "#{$1}\;#{$2}" end
- mpdata.gsub!(/(\".*?)@@@(.*?\")/o) do "#{$1};#{$2}" end
+ # mpdata.gsub!(/\n+/o, "\n")
+ # mpdata.gsub!(/(btex.*?)\@\@\@(.*?etex)/o) do "#{$1}\;#{$2}" end
+ # mpdata.gsub!(/(\".*?)\@\@\@(.*?\")/mo) do "#{$1};#{$2}" end
+ mpdata.gsub!(/\@\@\@/o) do ";" end
if mergebe then
mpdata.gsub!(/beginfig\s*\((\d+)\)\s*\;(.*?)endfig\s*\;/o) do
n, str = $1, $2
@@ -1451,12 +1453,12 @@ class TEX
mponame = File.suffixed(mpname,'mpo')
mpyname = File.suffixed(mpname,'mpy')
return false unless File.atleast?(mponame,32)
- mpochecksum = State.new.checksum(mponame)
+ mpochecksum = FileState.new.checksum(mponame)
return false if mpochecksum.empty?
# where does the checksum get into the file?
# maybe let texexec do it?
# solution: add one if not present or update when different
- if f = File.open(mpyname) then
+ if f = File.silentopen(mpyname) then
str = f.gets.chomp
f.close
if str =~ /^\%\s*mpochecksum\s*\:\s*(\d+)/o then
@@ -1469,15 +1471,12 @@ class TEX
def checkmplabels(mpname)
mpname = File.suffixed(mpname,'mpt')
- if File.atleast?(mpname,10) && (mp = File.open(mpname)) then
+ if File.atleast?(mpname,10) && (mp = File.silentopen(mpname)) then
labels = Hash.new
while str = mp.gets do
- if str =~ /%\s*setup\s*:\s*(.*)/o then
- t = $1
- else
- t = ''
- end
+ t = if str =~ /%\s*setup\s*:\s*(.*)/o then $1 else '' end
if str =~ /%\s*figure\s*(\d+)\s*:\s*(.*)/o then
+ labels[$1] = labels[$1] || ''
unless t.empty? then
labels[$1] += "#{t}\n"
t = ''
diff --git a/scripts/context/ruby/ctxtools.rb b/scripts/context/ruby/ctxtools.rb
index 41489a13d..7e1b6fa7a 100644
--- a/scripts/context/ruby/ctxtools.rb
+++ b/scripts/context/ruby/ctxtools.rb
@@ -17,7 +17,7 @@
#
# todo: move kpse call to kpse class/module
-banner = ['CtxTools', 'version 1.2.2', '2004/2005', 'PRAGMA ADE/POD']
+banner = ['CtxTools', 'version 1.3.0', '2004/2005', 'PRAGMA ADE/POD']
unless defined? ownpath
ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'')
@@ -1322,6 +1322,114 @@ class Commands
end
+class Array
+
+ def add_shebang(filename,program)
+ unless self[0] =~ /^\#!/ then
+ self.insert(0,"\#!/usr/env #{program}")
+ end
+ unless self[2] =~ /^\#.*?copyright\=/ then
+ self.insert(1,"\#")
+ self.insert(2,"\# copyright=pragma-ade readme=readme.pdf licence=cc-gpl")
+ self.insert(3,"") unless self[3].chomp.strip.empty?
+ self[2].gsub!(/ +/, ' ')
+ return true
+ else
+ return false
+ end
+ end
+
+ def add_directive(filename,program)
+ unless self[0] =~ /^\%/ then
+ self.insert(0,"\% content=#{program}")
+ end
+ unless self[2] =~ /^\%.*?copyright\=/ then
+ self.insert(1,"\%")
+ if File.expand_path(filename) =~ /[\\\/](doc|manuals)[\\\/]/ then
+ self.insert(2,"\% copyright=pragma-ade readme=readme.pdf licence=cc-by-nc-sa")
+ else
+ self.insert(2,"\% copyright=pragma-ade readme=readme.pdf licence=cc-gpl")
+ end
+ self.insert(3,"") unless self[3].chomp.strip.empty?
+ self[0].gsub!(/ +/, ' ')
+ return true
+ else
+ return false
+ end
+ end
+
+ def add_comment(filename)
+ if self[0] =~ /<\?xml.*?\?>/ && self[2] !~ /^<\!\-\-.*?copyright\=.*?\-\->/ then
+ self.insert(1,"")
+ if File.expand_path(filename) =~ /[\\\/](doc|manuals)[\\\/]/ then
+ self.insert(2,"<!-- copyright='pragma-ade' readme='readme.pdf' licence='cc-by-nc-sa' -->")
+ else
+ self.insert(2,"<!-- copyright='pragma-ade' readme='readme.pdf' licence='cc-gpl' -->")
+ end
+ self.insert(3,"") unless self[3].chomp.strip.empty?
+ return true
+ else
+ return false
+ end
+ end
+
+end
+
+class Commands
+
+ include CommandBase
+
+ def brandfiles
+
+ force = @commandline.option("force")
+ files = @commandline.arguments # Dir.glob("**/*.*")
+ done = false
+
+ files.each do |filename|
+ ok = false
+ begin
+ data = IO.readlines(filename)
+ case filename
+ when /\.rb$/ then
+ ok = data.add_shebang(filename,'ruby')
+ when /\.pl$/ then
+ ok = data.add_shebang(filename,'perl')
+ when /\.py$/ then
+ ok = data.add_shebang(filename,'python')
+ when /\.lua$/ then
+ ok = data.add_shebang(filename,'lua')
+ when /\.tex$/ then
+ ok = data.add_directive(filename,'tex')
+ when /\.mp$/ then
+ ok = data.add_directive(filename,'metapost')
+ when /\.mf$/ then
+ ok = data.add_directive(filename,'metafont')
+ when /\.(xml|xsl|fo|fx|rlx|rng|exa)$/ then
+ ok = data.add_comment(filename)
+ end
+ rescue
+ report("fatal error in processing #{filename}") # maybe this catches the mac problem taco reported
+ else
+ if ok then
+ report()
+ report(filename)
+ report()
+ for i in 0..4 do
+ report(' ' + data[i].chomp)
+ end
+ if force && f = File.open(filename,'w') then
+ f.puts data
+ f.close
+ end
+ done = true
+ end
+ end
+ end
+ report() if done
+ end
+
+end
+
class Commands
include CommandBase
@@ -1393,6 +1501,8 @@ commandline.registeraction('patternfiles', 'generate pattern files [--all --xml
commandline.registeraction('dpxmapfiles', 'convert pdftex mapfiles to dvipdfmx [--force] [texmfroot]')
commandline.registeraction('listentities', 'create doctype entity definition from enco-uc.tex')
+commandline.registeraction('brandfiles', 'add context copyright notice [--force]')
+
commandline.registervalue('type','')
commandline.registerflag('recurse')