diff options
author | Hans Hagen <pragma@wxs.nl> | 2018-06-22 16:42:14 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2018-06-22 16:42:14 +0200 |
commit | da8162d4e816cf49d9790a1c81556b499f442bed (patch) | |
tree | 5c631b1fb8282670a6cea1087afa766a8b94db43 /scripts | |
parent | 204057fdc5023b5f4ff55a69bc6593388ea427e7 (diff) | |
download | context-da8162d4e816cf49d9790a1c81556b499f442bed.tar.gz |
2018-06-22 16:02:00
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/mtx-package.lua | 20 | ||||
-rw-r--r-- | scripts/context/lua/mtx-pdf.lua | 63 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 18 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 18 | ||||
-rw-r--r-- | scripts/context/stubs/unix/mtxrun | 18 | ||||
-rw-r--r-- | scripts/context/stubs/win64/mtxrun.lua | 18 |
6 files changed, 73 insertions, 82 deletions
diff --git a/scripts/context/lua/mtx-package.lua b/scripts/context/lua/mtx-package.lua index c4487faec..6307e91e0 100644 --- a/scripts/context/lua/mtx-package.lua +++ b/scripts/context/lua/mtx-package.lua @@ -71,13 +71,19 @@ function scripts.package.merge_luatex_files(name) end collected = table.concat(collected) if environment.argument("stripcontext") then - local n = 0 - collected = string.gsub(collected,"\nif context then.-\nend",function(s) - n = n + #s - return "" - end) - if n > 0 then - report("%i context specific bytes stripped",n) + local stripped = 0 + local eol = lpeg.patterns.eol + local space = lpeg.patterns.space^0 + local start = eol * lpeg.P("if context then") * space * eol + local stop = eol * (lpeg.P("else") + lpeg.P("end")) * space * eol + local noppes = function() + stripped = striped + 1 + return "\n--removed\n" + end + local pattern = lpeg.Cs((start * ((1-stop)^1/noppes) * stop + lpeg.P(1))^0) + collected = lpeg.match(pattern,collected) + if stripped > 0 then + report("%i context specific sections stripped",stripped) end end report("saving %q (%i bytes)",newname,#collected) diff --git a/scripts/context/lua/mtx-pdf.lua b/scripts/context/lua/mtx-pdf.lua index ca0d2ea6b..a6364cfc9 100644 --- a/scripts/context/lua/mtx-pdf.lua +++ b/scripts/context/lua/mtx-pdf.lua @@ -27,7 +27,6 @@ local helpinfo = [[ <flag name="metadata"><short>show metadata xml blob</short></flag> <flag name="pretty"><short>replace newlines in metadata</short></flag> <flag name="fonts"><short>show used fonts (<ref name="detail)"/></short></flag> - <flag name="linearize"><short>linearize given file</short></flag> </subcategory> <subcategory> <example><command>mtxrun --script pdf --info foo.pdf</command></example> @@ -47,7 +46,11 @@ local application = logs.application { local report = application.report -dofile(resolvers.findfile("lpdf-epd.lua","tex")) +if pdfe then + dofile(resolvers.findfile("lpdf-pde.lua","tex")) +else + dofile(resolvers.findfile("lpdf-epd.lua","tex")) +end scripts = scripts or { } scripts.pdf = scripts.pdf or { } @@ -73,7 +76,7 @@ function scripts.pdf.info(filename) local catalog = pdffile.Catalog local info = pdffile.Info local pages = pdffile.pages - local nofpages = pages.n -- no # yet. will be in 5.2 + local nofpages = pdffile.nofpages report("filename > %s",filename) report("pdf version > %s",catalog.Version) @@ -119,7 +122,7 @@ function scripts.pdf.metadata(filename,pretty) end end -local expand = lpdf.epdf.expand +local expanded = lpdf.epdf.expanded local function getfonts(pdffile) local usedfonts = { } @@ -129,20 +132,20 @@ local function getfonts(pdffile) if resources then local fontlist = resources.Font if fontlist then - for k, v in next, expand(fontlist) do - usedfonts[tag and (tag .. "." .. k) or k] = expand(v,k) + for k, v in expanded(fontlist) do + usedfonts[tag and (tag .. "." .. k) or k] = v end end local objects = resources.XObject if objects then - for k, v in next, expand(objects) do + for k, v in expanded(objects) do collect(v,tag and (tag .. "." .. k) or k) end end end end - for i=1,pdffile.pages.n do + for i=1,pdffile.nofpages do collect(pdffile.pages[i]) end @@ -265,46 +268,6 @@ function scripts.pdf.fonts(filename) end end --- this is a quick hack ... proof of concept .. will change (derived from luigi's example) ... --- i will make a ctx wrapper - --- local qpdf -- just call qpdf, no need for a lib here --- --- function scripts.pdf.linearize(filename) --- qpdf = qpdf or swiglib("qpdf.core") --- local oldfile = filename or environment.files[1] --- if not oldfile then --- return --- end --- file.addsuffix(oldfile,"pdf") --- if not lfs.isfile(oldfile) then --- return --- end --- local newfile = environment.files[2] --- if not newfile or file.removesuffix(oldfile) == file.removesuffix(newfile)then --- newfile = file.addsuffix(file.removesuffix(oldfile) .. "-linearized","pdf") --- end --- local password = environment.arguments.password --- local instance = qpdf.qpdf_init() --- if bit32.band(qpdf.qpdf_read(instance,oldfile,password),qpdf.QPDF_ERRORS) ~= 0 then --- report("unable to open input file") --- elseif bit32.band(qpdf.qpdf_init_write(instance,newfile),qpdf.QPDF_ERRORS) ~= 0 then --- report("unable to open output file") --- else --- report("linearizing %a into %a",oldfile,newfile) --- qpdf.qpdf_set_static_ID(instance,qpdf.QPDF_TRUE) --- qpdf.qpdf_set_linearization(instance,qpdf.QPDF_TRUE) --- qpdf.qpdf_write(instance) --- end --- while qpdf.qpdf_more_warnings(instance) ~= 0 do --- report("warning: %s",qpdf.qpdf_get_error_full_text(instance,qpdf.qpdf_next_warning(qpdf))) --- end --- if qpdf.qpdf_has_error(instance) ~= 0 then --- report("error: %s",qpdf.qpdf_get_error_full_text(instance,qpdf.qpdf_get_error(qpdf))) --- end --- qpdf.qpdf_cleanup_p(instance) --- end - -- scripts.pdf.info("e:/tmp/oeps.pdf") -- scripts.pdf.metadata("e:/tmp/oeps.pdf") -- scripts.pdf.fonts("e:/tmp/oeps.pdf") @@ -317,11 +280,9 @@ if filename == "" then elseif environment.argument("info") then scripts.pdf.info(filename) elseif environment.argument("metadata") then - scripts.pdf.metadata(filename) + scripts.pdf.metadata(filename,environment.argument("pretty")) elseif environment.argument("fonts") then scripts.pdf.fonts(filename) --- elseif environment.argument("linearize") then --- scripts.pdf.linearize(filename) elseif environment.argument("exporthelp") then application.export(environment.argument("exporthelp"),filename) else diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 195f98afd..b0dfffe42 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1005,7 +1005,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 39398, stripped down to: 21142 +-- original size: 39415, stripped down to: 21143 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -1163,7 +1163,7 @@ patterns.cpfloat=sign^-1*patterns.cpunsigned patterns.number=patterns.float+patterns.integer patterns.cnumber=patterns.cfloat+patterns.integer patterns.cpnumber=patterns.cpfloat+patterns.integer -patterns.oct=zero*octdigits +patterns.oct=zero*octdigits patterns.octal=patterns.oct patterns.HEX=zero*P("X")*(digit+uppercase)^1 patterns.hex=zero*P("x")*(digit+lowercase)^1 @@ -6171,7 +6171,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 40725, stripped down to: 23032 +-- original size: 41277, stripped down to: 23383 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6524,6 +6524,7 @@ local sequenced=table.sequenced local formattednumber=number.formatted local sparseexponent=number.sparseexponent local formattedfloat=number.formattedfloat +local stripper=lpeg.patterns.stripzeros ]] else environment={ @@ -6549,6 +6550,7 @@ else formattednumber=number.formatted, sparseexponent=number.sparseexponent, formattedfloat=number.formattedfloat, + stripper=lpeg.patterns.stripzeros, } end local arguments={ "a1" } @@ -6759,7 +6761,11 @@ local format_n=function() end local format_N=function() n=n+1 - return format("tostring(tonumber(a%s) or a%s)",n,n) + if not f or f=="" then + return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or ((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%.9f',a%s)))",n,n,n,n,n) + else + return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%%sf',a%s)))",n,n,f,n) + end end local format_a=function(f) n=n+1 @@ -21640,8 +21646,8 @@ end -- of closure -- used libraries : l-lua.lua l-macro.lua l-sandbox.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-tpl.lua util-sbx.lua util-mrg.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 889120 --- stripped bytes : 321251 +-- original bytes : 889689 +-- stripped bytes : 321468 -- end library merge diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 195f98afd..b0dfffe42 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -1005,7 +1005,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 39398, stripped down to: 21142 +-- original size: 39415, stripped down to: 21143 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -1163,7 +1163,7 @@ patterns.cpfloat=sign^-1*patterns.cpunsigned patterns.number=patterns.float+patterns.integer patterns.cnumber=patterns.cfloat+patterns.integer patterns.cpnumber=patterns.cpfloat+patterns.integer -patterns.oct=zero*octdigits +patterns.oct=zero*octdigits patterns.octal=patterns.oct patterns.HEX=zero*P("X")*(digit+uppercase)^1 patterns.hex=zero*P("x")*(digit+lowercase)^1 @@ -6171,7 +6171,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 40725, stripped down to: 23032 +-- original size: 41277, stripped down to: 23383 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6524,6 +6524,7 @@ local sequenced=table.sequenced local formattednumber=number.formatted local sparseexponent=number.sparseexponent local formattedfloat=number.formattedfloat +local stripper=lpeg.patterns.stripzeros ]] else environment={ @@ -6549,6 +6550,7 @@ else formattednumber=number.formatted, sparseexponent=number.sparseexponent, formattedfloat=number.formattedfloat, + stripper=lpeg.patterns.stripzeros, } end local arguments={ "a1" } @@ -6759,7 +6761,11 @@ local format_n=function() end local format_N=function() n=n+1 - return format("tostring(tonumber(a%s) or a%s)",n,n) + if not f or f=="" then + return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or ((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%.9f',a%s)))",n,n,n,n,n) + else + return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%%sf',a%s)))",n,n,f,n) + end end local format_a=function(f) n=n+1 @@ -21640,8 +21646,8 @@ end -- of closure -- used libraries : l-lua.lua l-macro.lua l-sandbox.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-tpl.lua util-sbx.lua util-mrg.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 889120 --- stripped bytes : 321251 +-- original bytes : 889689 +-- stripped bytes : 321468 -- end library merge diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 195f98afd..b0dfffe42 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -1005,7 +1005,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 39398, stripped down to: 21142 +-- original size: 39415, stripped down to: 21143 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -1163,7 +1163,7 @@ patterns.cpfloat=sign^-1*patterns.cpunsigned patterns.number=patterns.float+patterns.integer patterns.cnumber=patterns.cfloat+patterns.integer patterns.cpnumber=patterns.cpfloat+patterns.integer -patterns.oct=zero*octdigits +patterns.oct=zero*octdigits patterns.octal=patterns.oct patterns.HEX=zero*P("X")*(digit+uppercase)^1 patterns.hex=zero*P("x")*(digit+lowercase)^1 @@ -6171,7 +6171,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 40725, stripped down to: 23032 +-- original size: 41277, stripped down to: 23383 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6524,6 +6524,7 @@ local sequenced=table.sequenced local formattednumber=number.formatted local sparseexponent=number.sparseexponent local formattedfloat=number.formattedfloat +local stripper=lpeg.patterns.stripzeros ]] else environment={ @@ -6549,6 +6550,7 @@ else formattednumber=number.formatted, sparseexponent=number.sparseexponent, formattedfloat=number.formattedfloat, + stripper=lpeg.patterns.stripzeros, } end local arguments={ "a1" } @@ -6759,7 +6761,11 @@ local format_n=function() end local format_N=function() n=n+1 - return format("tostring(tonumber(a%s) or a%s)",n,n) + if not f or f=="" then + return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or ((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%.9f',a%s)))",n,n,n,n,n) + else + return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%%sf',a%s)))",n,n,f,n) + end end local format_a=function(f) n=n+1 @@ -21640,8 +21646,8 @@ end -- of closure -- used libraries : l-lua.lua l-macro.lua l-sandbox.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-tpl.lua util-sbx.lua util-mrg.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 889120 --- stripped bytes : 321251 +-- original bytes : 889689 +-- stripped bytes : 321468 -- end library merge diff --git a/scripts/context/stubs/win64/mtxrun.lua b/scripts/context/stubs/win64/mtxrun.lua index 195f98afd..b0dfffe42 100644 --- a/scripts/context/stubs/win64/mtxrun.lua +++ b/scripts/context/stubs/win64/mtxrun.lua @@ -1005,7 +1005,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lpeg"] = package.loaded["l-lpeg"] or true --- original size: 39398, stripped down to: 21142 +-- original size: 39415, stripped down to: 21143 if not modules then modules={} end modules ['l-lpeg']={ version=1.001, @@ -1163,7 +1163,7 @@ patterns.cpfloat=sign^-1*patterns.cpunsigned patterns.number=patterns.float+patterns.integer patterns.cnumber=patterns.cfloat+patterns.integer patterns.cpnumber=patterns.cpfloat+patterns.integer -patterns.oct=zero*octdigits +patterns.oct=zero*octdigits patterns.octal=patterns.oct patterns.HEX=zero*P("X")*(digit+uppercase)^1 patterns.hex=zero*P("x")*(digit+lowercase)^1 @@ -6171,7 +6171,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-str"] = package.loaded["util-str"] or true --- original size: 40725, stripped down to: 23032 +-- original size: 41277, stripped down to: 23383 if not modules then modules={} end modules ['util-str']={ version=1.001, @@ -6524,6 +6524,7 @@ local sequenced=table.sequenced local formattednumber=number.formatted local sparseexponent=number.sparseexponent local formattedfloat=number.formattedfloat +local stripper=lpeg.patterns.stripzeros ]] else environment={ @@ -6549,6 +6550,7 @@ else formattednumber=number.formatted, sparseexponent=number.sparseexponent, formattedfloat=number.formattedfloat, + stripper=lpeg.patterns.stripzeros, } end local arguments={ "a1" } @@ -6759,7 +6761,11 @@ local format_n=function() end local format_N=function() n=n+1 - return format("tostring(tonumber(a%s) or a%s)",n,n) + if not f or f=="" then + return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or ((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%.9f',a%s)))",n,n,n,n,n) + else + return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%%sf',a%s)))",n,n,f,n) + end end local format_a=function(f) n=n+1 @@ -21640,8 +21646,8 @@ end -- of closure -- used libraries : l-lua.lua l-macro.lua l-sandbox.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-tpl.lua util-sbx.lua util-mrg.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 889120 --- stripped bytes : 321251 +-- original bytes : 889689 +-- stripped bytes : 321468 -- end library merge |