From 5ee86a080221db05e1dc12c361959e7d2fc5366b Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 29 Nov 2011 20:00:15 +0200 Subject: beta 2011.11.29 18:47 --- scripts/context/lua/mtx-epub.lua | 38 ++++++++++++++++---- scripts/context/lua/mtxrun.lua | 66 +++++++++++++++++++++++++++------- scripts/context/stubs/mswin/mtxrun.lua | 66 +++++++++++++++++++++++++++------- scripts/context/stubs/unix/mtxrun | 66 +++++++++++++++++++++++++++------- 4 files changed, 191 insertions(+), 45 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-epub.lua b/scripts/context/lua/mtx-epub.lua index 0dc533c4a..7d1c15774 100644 --- a/scripts/context/lua/mtx-epub.lua +++ b/scripts/context/lua/mtx-epub.lua @@ -164,6 +164,19 @@ local function locateimages(oldname,newname,subpath) return images end +local zippers = { + { + name = "zip", + uncompressed = "zip %s -X -0 %s", + compressed = "zip %s -X -9 -r %s", + }, + { + name = "7zip (7z)", + uncompressed = "7z a -tzip -mx0 %s %s", + compressed = "7z a -tzip %s %s", + }, +} + function scripts.epub.make() local filename = environment.files[1] @@ -248,19 +261,32 @@ function scripts.epub.make() io.savedata(file.join(epubpath,"OPS",epubroot),package) io.savedata(file.join(epubpath,"OPS",epubtoc),toc) - lfs.chdir(epubpath) - application.report("creating archive\n\n") + local done = false + local list = { } + + lfs.chdir(epubpath) os.remove(epubfile) - os.execute(format("zip %s -X -0 %s",epubfile,"mimetype")) - os.execute(format("zip %s -X -9 -r %s",epubfile,"META-INF")) - os.execute(format("zip %s -X -9 -r %s",epubfile,"OPS")) + for i=1,#zippers do + local zipper = zippers[i] + if os.execute(format(zipper.uncompressed,epubfile,"mimetype")) then + os.execute(format(zipper.compressed,epubfile,"META-INF")) + os.execute(format(zipper.compressed,epubfile,"OPS")) + done = zipper.name + else + list[#list+1] = zipper.name + end + end lfs.chdir("..") - application.report("epub archive: %s",file.join(epubpath,epubfile)) + if done then + application.report("epub archive made using %s: %s",done,file.join(epubpath,epubfile)) + else + application.report("no epub archive made, install one of: %s",concat(list," ")) + end end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 92e438188..fa68fb3fc 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -1639,32 +1639,72 @@ function lpeg.is_lpeg(p) return p and lpegtype(p) == "pattern" end --- For the moment here, but it might move to utilities: +-- For the moment here, but it might move to utilities. Beware, we need to +-- have the longest keyword first, so 'aaa' comes beforte 'aa' which is why we +-- loop back from the end. -local sort, fastcopy, sortedpairs = table.sort, table.fastcopy, table.sortedpairs -- dependency! +local sort, fastcopy, sortedkeys = table.sort, table.fastcopy, table.sortedkeys -- dependency! -function lpeg.append(list,pp,delayed) +function lpeg.append(list,pp,delayed,checked) local p = pp if #list > 0 then - list = fastcopy(list) - sort(list) - for l=1,#list do + local keys = fastcopy(list) + sort(keys) + for i=#keys,1,-1 do + local k = keys[i] if p then - p = P(list[l]) + p + p = P(k) + p else - p = P(list[l]) + p = P(k) end end - elseif delayed then - for k, v in sortedpairs(list) do - if p then + elseif delayed then -- hm, it looks like the lpeg parser resolves anyway + local keys = sortedkeys(list) + if p then + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] p = P(k)/list + p + end + else + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] + if p then + p = P(k) + p + else + p = P(k) + end + end + if p then + p = p / list + end + end + elseif checked then + -- problem: substitution gives a capture + local keys = sortedkeys(list) + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] + if p then + if k == v then + p = P(k) + p + else + p = P(k)/v + p + end else - p = P(k)/list + if k == v then + p = P(k) + else + p = P(k)/v + end end end else - for k, v in sortedpairs(list) do + local keys = sortedkeys(list) + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] if p then p = P(k)/v + p else diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 92e438188..fa68fb3fc 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -1639,32 +1639,72 @@ function lpeg.is_lpeg(p) return p and lpegtype(p) == "pattern" end --- For the moment here, but it might move to utilities: +-- For the moment here, but it might move to utilities. Beware, we need to +-- have the longest keyword first, so 'aaa' comes beforte 'aa' which is why we +-- loop back from the end. -local sort, fastcopy, sortedpairs = table.sort, table.fastcopy, table.sortedpairs -- dependency! +local sort, fastcopy, sortedkeys = table.sort, table.fastcopy, table.sortedkeys -- dependency! -function lpeg.append(list,pp,delayed) +function lpeg.append(list,pp,delayed,checked) local p = pp if #list > 0 then - list = fastcopy(list) - sort(list) - for l=1,#list do + local keys = fastcopy(list) + sort(keys) + for i=#keys,1,-1 do + local k = keys[i] if p then - p = P(list[l]) + p + p = P(k) + p else - p = P(list[l]) + p = P(k) end end - elseif delayed then - for k, v in sortedpairs(list) do - if p then + elseif delayed then -- hm, it looks like the lpeg parser resolves anyway + local keys = sortedkeys(list) + if p then + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] p = P(k)/list + p + end + else + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] + if p then + p = P(k) + p + else + p = P(k) + end + end + if p then + p = p / list + end + end + elseif checked then + -- problem: substitution gives a capture + local keys = sortedkeys(list) + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] + if p then + if k == v then + p = P(k) + p + else + p = P(k)/v + p + end else - p = P(k)/list + if k == v then + p = P(k) + else + p = P(k)/v + end end end else - for k, v in sortedpairs(list) do + local keys = sortedkeys(list) + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] if p then p = P(k)/v + p else diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 92e438188..fa68fb3fc 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -1639,32 +1639,72 @@ function lpeg.is_lpeg(p) return p and lpegtype(p) == "pattern" end --- For the moment here, but it might move to utilities: +-- For the moment here, but it might move to utilities. Beware, we need to +-- have the longest keyword first, so 'aaa' comes beforte 'aa' which is why we +-- loop back from the end. -local sort, fastcopy, sortedpairs = table.sort, table.fastcopy, table.sortedpairs -- dependency! +local sort, fastcopy, sortedkeys = table.sort, table.fastcopy, table.sortedkeys -- dependency! -function lpeg.append(list,pp,delayed) +function lpeg.append(list,pp,delayed,checked) local p = pp if #list > 0 then - list = fastcopy(list) - sort(list) - for l=1,#list do + local keys = fastcopy(list) + sort(keys) + for i=#keys,1,-1 do + local k = keys[i] if p then - p = P(list[l]) + p + p = P(k) + p else - p = P(list[l]) + p = P(k) end end - elseif delayed then - for k, v in sortedpairs(list) do - if p then + elseif delayed then -- hm, it looks like the lpeg parser resolves anyway + local keys = sortedkeys(list) + if p then + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] p = P(k)/list + p + end + else + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] + if p then + p = P(k) + p + else + p = P(k) + end + end + if p then + p = p / list + end + end + elseif checked then + -- problem: substitution gives a capture + local keys = sortedkeys(list) + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] + if p then + if k == v then + p = P(k) + p + else + p = P(k)/v + p + end else - p = P(k)/list + if k == v then + p = P(k) + else + p = P(k)/v + end end end else - for k, v in sortedpairs(list) do + local keys = sortedkeys(list) + for i=#keys,1,-1 do + local k = keys[i] + local v = list[k] if p then p = P(k)/v + p else -- cgit v1.2.3