From b32da8747292384893ea07a0a5659b24eb216c10 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 17 Jul 2009 13:16:00 +0200 Subject: stable 2009.07.17 13:16 --- scripts/context/lua/mtx-context.lua | 17 +++- scripts/context/lua/mtx-convert.lua | 132 +++++++++++++++++++------------ scripts/context/lua/mtx-grep.lua | 4 +- scripts/context/lua/mtx-texworks.lua | 96 ++++++++++++++++++++++ scripts/context/lua/mtx-tools.lua | 57 +++++++++++++ scripts/context/lua/mtx-update.lua | 27 ++++++- scripts/context/lua/mtxrun.lua | 9 +++ scripts/context/stubs/mswin/mtxrun.lua | 9 +++ scripts/context/stubs/mswin/mtxworks.cmd | 1 + scripts/context/stubs/unix/mtxrun | 9 +++ scripts/context/stubs/unix/mtxworks | 2 + 11 files changed, 308 insertions(+), 55 deletions(-) create mode 100644 scripts/context/lua/mtx-texworks.lua create mode 100644 scripts/context/lua/mtx-tools.lua create mode 100644 scripts/context/stubs/mswin/mtxworks.cmd create mode 100755 scripts/context/stubs/unix/mtxworks (limited to 'scripts') diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index 3e0abb1e7..71d2eee56 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -9,6 +9,13 @@ if not modules then modules = { } end modules ['mtx-context'] = { scripts = scripts or { } scripts.context = scripts.context or { } +-- a demo cld file: +-- +-- context.starttext() +-- context.chapter("Hello There") +-- context.readfile("tufte","","not found") +-- context.stoptext() + -- l-file / todo function file.needsupdate(oldfile,newfile) @@ -521,6 +528,10 @@ end -- end -- end +scripts.context.cldsuffixes = table.tohash { + "cld", +} + scripts.context.xmlsuffixes = table.tohash { "xml", } @@ -648,6 +659,7 @@ function scripts.context.run(ctxdata,filename) if a and (a.engine == 'pdftex' or a.engine == 'xetex' or environment.argument("pdftex") or environment.argument("xetex")) then local texexec = resolvers.find_file("texexec.rb") or "" if texexec ~= "" then + os.setenv("RUBYOPT","") local command = string.format("ruby %s %s",texexec,environment.reconstruct_commandline(environment.arguments_after)) os.exec(command) end @@ -672,7 +684,9 @@ function scripts.context.run(ctxdata,filename) else filename = makestub("\\xmlprocess{\\xmldocument}{%s}{}",filename) end - elseif scripts.context.luasuffixes[suffix] then + elseif scripts.context.cldsuffixes[suffix] or environment.argument("forcecld") then + filename = makestub("\\ctxlua{context.runfile('%s')}",filename) + elseif scripts.context.luasuffixes[suffix] or environment.argument("forcelua") then filename = makestub("\\ctxlua{dofile('%s')}",filename) end -- @@ -1333,6 +1347,7 @@ messages.help = [[ --ctx=name use ctx file --version report installed context version --forcexml force xml stub (optional flag: --mkii) +--forcecld force cld (context lua document) stub --autopdf close pdf file in viewer and start pdf viewer afterwards --once only one run --purge(all) purge files (--pattern=...) diff --git a/scripts/context/lua/mtx-convert.lua b/scripts/context/lua/mtx-convert.lua index cf1d640c5..c0c383b17 100644 --- a/scripts/context/lua/mtx-convert.lua +++ b/scripts/context/lua/mtx-convert.lua @@ -6,66 +6,88 @@ if not modules then modules = { } end modules ['mtx-convert'] = { license = "see context related readme files" } -do +-- todo: eps and svg - graphics = graphics or { } - graphics.converters = graphics.converters or { } +graphics = graphics or { } +graphics.converters = graphics.converters or { } - local gsprogram = (os.platform == "windows" and "gswin32c") or "gs" - local gstemplate = "%s -q -sDEVICE=pdfwrite -dEPSCrop -dNOPAUSE -dNOCACHE -dBATCH -dAutoRotatePages=/None -dProcessColorModel=/DeviceCMYK -sOutputFile=%s %s -c quit" +local gsprogram = (os.platform == "windows" and "gswin32c") or "gs" +local gstemplate = "%s -q -sDEVICE=pdfwrite -dEPSCrop -dNOPAUSE -dNOCACHE -dBATCH -dAutoRotatePages=/None -dProcessColorModel=/DeviceCMYK -sOutputFile=%s %s -c quit" - function graphics.converters.eps(oldname,newname) - return gstemplate:format(gsprogram,newname,oldname) - end +function graphics.converters.eps(oldname,newname) + return gstemplate:format(gsprogram,newname,oldname) +end - local improgram = "convert" - local imtemplate = { - low = "%s -quality 0 -compress zip %s pdf:%s", - medium = "%s -quality 75 -compress zip %s pdf:%s", - high = "%s -quality 100 -compress zip %s pdf:%s", - } - - function graphics.converters.jpg(oldname,newname) - local ea = environment.arguments - local quality = (ea.high and 'high') or (ea.medium and 'medium') or (ea.low and 'low') or 'high' - return imtemplate[quality]:format(improgram,oldname,newname) +local improgram = "convert" +local imtemplate = { + low = "%s -quality 0 -compress zip %s pdf:%s", + medium = "%s -quality 75 -compress zip %s pdf:%s", + high = "%s -quality 100 -compress zip %s pdf:%s", +} + +function graphics.converters.jpg(oldname,newname) + local ea = environment.arguments + local quality = (ea.high and 'high') or (ea.medium and 'medium') or (ea.low and 'low') or 'high' + return imtemplate[quality]:format(improgram,oldname,newname) +end + +graphics.converters.tif = graphics.converters.jpg +graphics.converters.tiff = graphics.converters.jpg +graphics.converters.png = graphics.converters.jpg + +local function convert(kind,oldname,newname) + if graphics.converters[kind] then -- extra test + local tmpname = file.replacesuffix(newname,"tmp") + local command = graphics.converters[kind](oldname,tmpname) + logs.simple("command: %s",command) + io.flush() + os.spawn(command) + os.remove(newname) + os.rename(tmpname,newname) + if lfs.attributes(newname,"size") == 0 then + os.remove(newname) + end end +end - graphics.converters.tif = graphics.converters.jpg - graphics.converters.tiff = graphics.converters.jpg - graphics.converters.png = graphics.converters.jpg - - function graphics.converters.convertpath(inputpath,outputpath) - inputpath = inputpath or "." - outputpath = outputpath or "." - for name in lfs.dir(inputpath) do - local suffix = file.extname(name) - if name:find("%.$") then - -- skip . and .. - elseif graphics.converters[suffix] then - local oldname = file.join(inputpath,name) - local newname = file.join(outputpath,file.replacesuffix(name,"pdf")) - local et = lfs.attributes(oldname,"modification") - local pt = lfs.attributes(newname,"modification") - if not pt or et > pt then - dir.mkdirs(outputpath) - local tmpname = file.replacesuffix(newname,"tmp") - local command = graphics.converters[suffix](oldname,tmpname) - logs.simple("command: %s",command) - io.flush() - os.spawn(command) - os.remove(newname) - os.rename(tmpname,newname) - if lfs.attributes(newname,"size") == 0 then - os.remove(newname) - end - end - elseif lfs.isdir(inputpath .. "/".. name) then - graphics.converters.convertpath(inputpath .. "/".. name,outputpath .. "/".. name) +function graphics.converters.convertpath(inputpath,outputpath) + inputpath = inputpath or "." + outputpath = outputpath or "." + for name in lfs.dir(inputpath) do + local suffix = file.extname(name) + if name:find("%.$") then + -- skip . and .. + elseif graphics.converters[suffix] then + local oldname = file.join(inputpath,name) + local newname = file.join(outputpath,file.replacesuffix(name,"pdf")) + local et = lfs.attributes(oldname,"modification") + local pt = lfs.attributes(newname,"modification") + if not pt or et > pt then + dir.mkdirs(outputpath) + convert(suffix,oldname,newname) end + elseif lfs.isdir(inputpath .. "/".. name) then + graphics.converters.convertpath(inputpath .. "/".. name,outputpath .. "/".. name) end end +end +function graphics.converters.convertfile(oldname) + local suffix = file.extname(oldname) + if graphics.converters[suffix] then + local newname = file.replacesuffix(name,"pdf") + if oldname == newname then + -- todo: downsample, crop etc + elseif environment.argument("force") then + convert(suffix,oldname,newname) + else + local et = lfs.attributes(oldname,"modification") + local pt = lfs.attributes(newname,"modification") + if not pt or et > pt then + convert(suffix,oldname,newname) + end + end + end end scripts = scripts or { } @@ -88,6 +110,13 @@ function scripts.convert.convertall() end end +function scripts.convert.convertgiven() + for _, name in ipairs(environment.files) do + graphics.converters.convertfile(name) + end +end + + logs.extendbanner("Graphic Conversion Tools 0.10",true) messages.help = [[ @@ -95,11 +124,14 @@ messages.help = [[ --inputpath=string original graphics path --outputpath=string converted graphics path --watch watch folders +--force force conversion (even if older) --delay time between sweeps ]] if environment.argument("convertall") then scripts.convert.convertall() +elseif environment.files[1] then + scripts.convert.convertgiven() else logs.help(messages.help) end diff --git a/scripts/context/lua/mtx-grep.lua b/scripts/context/lua/mtx-grep.lua index 82a80314a..a6617d711 100644 --- a/scripts/context/lua/mtx-grep.lua +++ b/scripts/context/lua/mtx-grep.lua @@ -44,7 +44,7 @@ function scripts.grep.find(pattern, files, offset) -- skip elseif find(line,pattern) then m = m + 1 - write_nl(format("%s %s: %s",name,n,line)) + write_nl(format("%s %6i: %s",name,n,line)) io.flush() end end @@ -62,7 +62,7 @@ function scripts.grep.find(pattern, files, offset) n = n + 1 if find(line,pattern) then m = m + 1 - write_nl(format("%s %s: %s",name,n,line)) + write_nl(format("%s %6i: %s",name,n,line)) io.flush() end end diff --git a/scripts/context/lua/mtx-texworks.lua b/scripts/context/lua/mtx-texworks.lua new file mode 100644 index 000000000..f525d5336 --- /dev/null +++ b/scripts/context/lua/mtx-texworks.lua @@ -0,0 +1,96 @@ +if not modules then modules = { } end modules ['mtx-texworks'] = { + version = 1.002, + comment = "companion to mtxrun.lua", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +scripts = scripts or { } +scripts.texworks = scripts.texworks or { } + +local texworkspaths = { + "completion", + "configuration", + "dictionaries", + "translations", + "scripts", + "templates", + "TUG" +} + +local texworkssignal = "texworks-context.rme" +local texworkininame = "TeXworks.ini" + +function scripts.texworks.start(indeed) + local is_mswin = os.platform == "windows" + local workname = (is_mswin and "texworks.exe") or "TeXworks" + local fullname = nil + local binpaths = file.split_path(os.getenv("PATH")) or file.split_path(os.getenv("path")) + local datapath = resolvers.find_file(texworkssignal,"other text files") or "" + if datapath ~= "" then + datapath = file.dirname(datapath) -- data + if datapath == "" then + datapath = resolvers.ownpath + end + else + datapath = resolvers.find_file(texworkininame,"other text files") or "" + if datapath == "" then + datapath = resolvers.find_file(string.lower(texworkininame),"other text files") or "" + end + if datapath ~= "" and lfs.isfile(datapath) then + datapath = file.dirname(datapath) -- TUG + datapath = file.dirname(datapath) -- data + if datapath == "" then + datapath = resolvers.ownpath + end + end + end + if datapath == "" then + logs.simple("invalid datapath, maybe you need to regenerate the file database") + return false + end + if not binpaths or #binpaths == 0 then + logs.simple("invalid binpath") + return false + end + for i=1,#binpaths do + local p = file.join(binpaths[i],workname) + if lfs.isfile(p) then + fullname = p + break + end + end + if not fullname then + logs.simple("unable to locate %s",workname) + return false + end + for _, subpath in ipairs(texworkspaths) do + dir.makedirs(file.join(datapath,subpath)) + end + os.setenv("TW_INIPATH",datapath) + os.setenv("TW_LIBPATH",datapath) + if not indeed or environment.argument("verbose") then + logs.simple("data path: %s", datapath) + logs.simple("full name: %s", fullname) + end + if indeed then + os.launch(fullname) + end +end + + +logs.extendbanner("TeXworks startup script 1.0",true) + +messages.help = [[ +--start [--verbose] start texworks +--test report what will happen +]] + +if environment.argument("start") then + scripts.texworks.start(true) +elseif environment.argument("test") then + scripts.texworks.start() +else + logs.help(messages.help) +end diff --git a/scripts/context/lua/mtx-tools.lua b/scripts/context/lua/mtx-tools.lua new file mode 100644 index 000000000..87fd51dc6 --- /dev/null +++ b/scripts/context/lua/mtx-tools.lua @@ -0,0 +1,57 @@ +if not modules then modules = { } end modules ['mtx-tools'] = { + version = 1.002, + comment = "companion to mtxrun.lua", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- data tables by Thomas A. Schmitz + +local find, gsub = string.find, string.gsub + +scripts = scripts or { } +scripts.tools = scripts.tools or { } + +local bomb_1, bomb_2 = "^\254\255", "^\239\187\191" + +function scripts.tools.disarmutfbomb() + local force, done = environment.argument("force"), false + for _, name in ipairs(environment.files) do + if lfs.isfile(name) then + local data = io.loaddata(name) + if not data then + -- just skip + elseif find(data,bomb_1) then + logs.simple("file '%s' has a 2 character utf bomb",name) + if force then + io.savedata(name,(gsub(data,bomb_1,""))) + end + done = true + elseif find(data,bomb_2) then + logs.simple("file '%s' has a 3 character utf bomb",name) + if force then + io.savedata(name,(gsub(data,bomb_2,""))) + end + done = true + else + -- logs.simple("file '%s' has no utf bomb",name) + end + end + end + if done and not force then + logs.simple("use --force to do a real disarming") + end +end + +logs.extendbanner("All Kind Of Tools 1.0",true) + +messages.help = [[ +--disarmutfbomb remove utf bomb if present +]] + +if environment.argument("disarmutfbomb") then + scripts.tools.disarmutfbomb() +else + logs.help(messages.help) +end diff --git a/scripts/context/lua/mtx-update.lua b/scripts/context/lua/mtx-update.lua index 66f6898d3..bc6ca4026 100644 --- a/scripts/context/lua/mtx-update.lua +++ b/scripts/context/lua/mtx-update.lua @@ -102,6 +102,15 @@ scripts.update.engines = { }, } +scripts.update.goodies = { + ["scite"] = { + { "bin//scite/", "texmf-" }, + }, + ["texworks"] = { + { "bin//texworks/", "texmf-" }, + }, +} + scripts.update.platforms = { ["mswin"] = "mswin", ["windows"] = "mswin", @@ -163,7 +172,8 @@ function scripts.update.synchronize() local bin = states.get("rsync.program") -- rsync local url = states.get("rsync.server") -- contextgarden.net local version = states.get("context.version") -- current (or beta) - local extras = states.get("extras") -- extra goodies (like modules) + local extras = states.get("extras") -- extras (like modules) + local goodies = states.get("goodies") -- goodies (like editors) local force = environment.argument("force") bin = string.gsub(bin,"\\","/") @@ -285,6 +295,14 @@ function scripts.update.synchronize() end end + if goodies and type(goodies) == "table" then + for goodie, _ in pairs(goodies) do + for platform, _ in pairs(platforms) do + add_collection(scripts.update.goodies[goodie],platform) + end + end + end + local combined = { } for _, repository in ipairs(scripts.update.repositories) do if repositories[repository] then @@ -374,7 +392,8 @@ function scripts.update.make() local force = environment.argument("force") local texroot = scripts.update.fullpath(states.get("paths.root")) - local engines= states.get('engines') + local engines = states.get('engines') + local goodies = states.get('goodies') local platforms = states.get('platforms') local formats = states.get('formats') @@ -431,6 +450,7 @@ messages.help = [[ --texroot=string installation directory (not guessed for the moment) --engine=string tex engine (luatex, pdftex, xetex) --extras=string extra modules (can be list or 'all') +--goodies=string extra binaries (like scite and texworks) --force instead of a dryrun, do the real thing --update update minimal tree --make also make formats and generate file databases @@ -500,6 +520,9 @@ if scripts.savestate then for r in gmatch(environment.argument("extras") or "","([^, ]+)") do states.set("extras." .. r, true) end + for r in gmatch(environment.argument("goodies") or "","([^, ]+)") do + states.set("goodies." .. r, true) + end logs.report("state","loaded") diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 0c96ed446..d30350ea5 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -10070,6 +10070,12 @@ function runners.execute_ctx_script(filename,arguments) end end +function runners.timedrun(filename) -- just for me + if filename and filename ~= "" then + runners.timed(function() os.execute(filename) end) + end +end + function runners.timed(action) statistics.timed(action) end @@ -10197,6 +10203,9 @@ elseif environment.argument("locate") then elseif environment.argument("platform")then -- locate platform runners.locate_platform() +elseif environment.argument("timedrun") then + -- locate platform + runners.timedrun(filename) elseif environment.argument("help") or filename=='help' or filename == "" then logs.help(messages.help) -- execute script diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 0c96ed446..d30350ea5 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -10070,6 +10070,12 @@ function runners.execute_ctx_script(filename,arguments) end end +function runners.timedrun(filename) -- just for me + if filename and filename ~= "" then + runners.timed(function() os.execute(filename) end) + end +end + function runners.timed(action) statistics.timed(action) end @@ -10197,6 +10203,9 @@ elseif environment.argument("locate") then elseif environment.argument("platform")then -- locate platform runners.locate_platform() +elseif environment.argument("timedrun") then + -- locate platform + runners.timedrun(filename) elseif environment.argument("help") or filename=='help' or filename == "" then logs.help(messages.help) -- execute script diff --git a/scripts/context/stubs/mswin/mtxworks.cmd b/scripts/context/stubs/mswin/mtxworks.cmd new file mode 100644 index 000000000..322d9464d --- /dev/null +++ b/scripts/context/stubs/mswin/mtxworks.cmd @@ -0,0 +1 @@ +mtxrun --script texworks --start diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 0c96ed446..d30350ea5 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -10070,6 +10070,12 @@ function runners.execute_ctx_script(filename,arguments) end end +function runners.timedrun(filename) -- just for me + if filename and filename ~= "" then + runners.timed(function() os.execute(filename) end) + end +end + function runners.timed(action) statistics.timed(action) end @@ -10197,6 +10203,9 @@ elseif environment.argument("locate") then elseif environment.argument("platform")then -- locate platform runners.locate_platform() +elseif environment.argument("timedrun") then + -- locate platform + runners.timedrun(filename) elseif environment.argument("help") or filename=='help' or filename == "" then logs.help(messages.help) -- execute script diff --git a/scripts/context/stubs/unix/mtxworks b/scripts/context/stubs/unix/mtxworks new file mode 100755 index 000000000..ef8f230c3 --- /dev/null +++ b/scripts/context/stubs/unix/mtxworks @@ -0,0 +1,2 @@ +#!/bin/sh +mtxrun --script texworks --start -- cgit v1.2.3