diff options
Diffstat (limited to 'tex')
52 files changed, 484 insertions, 242 deletions
diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index ccba6be79..64f238b14 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2018.02.25 19:48} +\newcontextversion{2018.03.06 14:59} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii index 4c8a44aac..59c766e6d 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2018.02.25 19:48} +\edef\contextversion{2018.03.06 14:59} %D For those who want to use this: diff --git a/tex/context/base/mkii/mult-pe.mkii b/tex/context/base/mkii/mult-pe.mkii index 5115758ec..534c239da 100644 --- a/tex/context/base/mkii/mult-pe.mkii +++ b/tex/context/base/mkii/mult-pe.mkii @@ -1077,6 +1077,7 @@ \setinterfaceconstant{preview}{پیشدید} \setinterfaceconstant{previous}{قبلی} \setinterfaceconstant{previousnumber}{شمارهقبلی} +\setinterfaceconstant{print}{print} \setinterfaceconstant{printable}{قابلچاپ} \setinterfaceconstant{process}{پردازش} \setinterfaceconstant{profile}{profile} diff --git a/tex/context/base/mkiv/char-ini.lua b/tex/context/base/mkiv/char-ini.lua index a2bb9694c..c308a2c0f 100644 --- a/tex/context/base/mkiv/char-ini.lua +++ b/tex/context/base/mkiv/char-ini.lua @@ -1066,7 +1066,7 @@ setmetatableindex(descriptions, function(t,k) for u, c in next, data do local d = c.description if d then - if find(d," ") then + if find(d," ",1,true) then d = gsub(d," ","") end d = lower(d) @@ -1084,7 +1084,7 @@ setmetatableindex(synonyms, function(t,k) for u, c in next, data do local s = c.synonyms if s then - if find(s," ") then + if find(s," ",1,true) then s = gsub(s," ","") end -- s = lower(s) -- is already lowercase diff --git a/tex/context/base/mkiv/char-tex.lua b/tex/context/base/mkiv/char-tex.lua index 9fab2c8a4..f123f0092 100644 --- a/tex/context/base/mkiv/char-tex.lua +++ b/tex/context/base/mkiv/char-tex.lua @@ -328,7 +328,7 @@ local ligaturemapping = allocate { -- } -- -- function texcharacters.toutf(str,strip) --- if not find(str,"\\") then +-- if not find(str,"\\",1,true) then -- return str -- elseif strip then -- return lpegmatch(both_1,str) @@ -380,7 +380,7 @@ end function texcharacters.toutf(str,strip) if str == "" then return str - elseif not find(str,"\\") then + elseif not find(str,"\\",1,true) then return str -- elseif strip then else diff --git a/tex/context/base/mkiv/cont-fil.mkiv b/tex/context/base/mkiv/cont-fil.mkiv index ed1a873f3..9257e2e1e 100644 --- a/tex/context/base/mkiv/cont-fil.mkiv +++ b/tex/context/base/mkiv/cont-fil.mkiv @@ -109,6 +109,9 @@ \definefilesynonym [art-01] [article-basic] \definefilesynonym [article] [article-basic] \definefilesynonym [mag-01] [magazine-basic] +\definefilesynonym [magazine] [magazine-basic] +\definefilesynonym [mod-01] [module-basic] +\definefilesynonym [module] [module-basic] \definefilesynonym [map-10] [maps] % for a while @@ -139,8 +142,6 @@ \definefilesynonym [syn-01] [syntax] -\definefilesynonym [mod-01] [modules-basics] - \definefilesynonym [reg-01] [regimes-list] \definefilesynonym [set-11] [setups-basics] diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index f88f14fa6..185b10341 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2018.02.25 19:48} +\newcontextversion{2018.03.06 14:59} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index c5122398c..2fc4222bb 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -42,7 +42,7 @@ %D has to match \type {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2018.02.25 19:48} +\edef\contextversion{2018.03.06 14:59} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/mkiv/data-aux.lua b/tex/context/base/mkiv/data-aux.lua index dae96ce62..1e020d1e8 100644 --- a/tex/context/base/mkiv/data-aux.lua +++ b/tex/context/base/mkiv/data-aux.lua @@ -38,7 +38,7 @@ function resolvers.updatescript(oldname,newname) -- oldname -> own.name, not per if trace_locating then report_scripts("old and new script are the same") end - elseif not find(newscript,scriptpath) then + elseif not find(newscript,scriptpath,1,true) then if trace_locating then report_scripts("new script should come from %a",scriptpath) end diff --git a/tex/context/base/mkiv/file-mod.lua b/tex/context/base/mkiv/file-mod.lua index 3bbc28727..81320f96e 100644 --- a/tex/context/base/mkiv/file-mod.lua +++ b/tex/context/base/mkiv/file-mod.lua @@ -137,7 +137,7 @@ function environment.usemodules(prefix,askedname,truename) end if status then -- ok, don't change - elseif find(truename,"%-") and usemodule(truename) then + elseif find(truename,"-",1,true) and usemodule(truename) then -- assume a user namespace report("using user prefixed file %a",truename) status = 1 diff --git a/tex/context/base/mkiv/font-con.lua b/tex/context/base/mkiv/font-con.lua index 86c98c16d..9cffa5927 100644 --- a/tex/context/base/mkiv/font-con.lua +++ b/tex/context/base/mkiv/font-con.lua @@ -333,7 +333,7 @@ local psfake = 0 local function fixedpsname(psname,fallback) local usedname = psname if psname and psname ~= "" then - if find(psname," ") then + if find(psname," ",1,true) then usedname = gsub(psname,"[%s]+","-") else -- we assume that the name is sane enough (we might sanitize completely some day) diff --git a/tex/context/base/mkiv/font-onr.lua b/tex/context/base/mkiv/font-onr.lua index f1cdefa1b..26a782649 100644 --- a/tex/context/base/mkiv/font-onr.lua +++ b/tex/context/base/mkiv/font-onr.lua @@ -185,7 +185,7 @@ do return end - if not (find(data,"!PS%-AdobeFont%-") or find(data,"%%!FontType1")) then + if not (find(data,"!PS-AdobeFont-",1,true) or find(data,"%!FontType1",1,true)) then report_pfb("no font in %a",filename) return end diff --git a/tex/context/base/mkiv/font-syn.lua b/tex/context/base/mkiv/font-syn.lua index 4a9b81be2..52f425db3 100644 --- a/tex/context/base/mkiv/font-syn.lua +++ b/tex/context/base/mkiv/font-syn.lua @@ -14,6 +14,8 @@ if not modules then modules = { } end modules ['font-syn'] = { -- old ff loader: 140 sec -- new lua loader: 5 sec +-- maybe find(...,strictname,1,true) + local next, tonumber, type, tostring = next, tonumber, type, tostring local sub, gsub, match, find, lower, upper = string.sub, string.gsub, string.match, string.find, string.lower, string.upper local concat, sort, fastcopy, tohash = table.concat, table.sort, table.fastcopy, table.tohash @@ -394,11 +396,11 @@ filters.ttc = filters.otf -- local hash = { } -- local okay = false -- for line in f:lines() do -- slow but only a few lines at the beginning --- if find(line,"dict begin") then +-- if find(line,"dict begin",1,true) then -- okay = true -- elseif not okay then -- -- go on --- elseif find(line,"currentdict end") then +-- elseif find(line,"currentdict end",1,true) then -- break -- else -- local key, value = lpegmatch(p_entry,line) diff --git a/tex/context/base/mkiv/grph-inc.lua b/tex/context/base/mkiv/grph-inc.lua index 5f403ebc7..71ee2f7ea 100644 --- a/tex/context/base/mkiv/grph-inc.lua +++ b/tex/context/base/mkiv/grph-inc.lua @@ -917,7 +917,6 @@ local function locate(request) -- name, format, cache askedname = path end else - -- local fname = methodhandler('finders',pathname .. "/" .. wantedfiles[k]) local foundname = resolvers.findbinfile(askedname) if not foundname or not lfs.isfile(foundname) then -- foundname can be dummy if trace_figures then @@ -1809,7 +1808,7 @@ end local function bases_locate(askedlabel) for i=1,#bases_list do local entry = bases_list[i] - local t = bases_find(entry[1],askedlabel) + local t = bases_find(entry[1],askedlabel,1,true) if t then return t end diff --git a/tex/context/base/mkiv/l-bit32.lua b/tex/context/base/mkiv/l-bit32.lua index 592c48f8e..5f35b8fee 100644 --- a/tex/context/base/mkiv/l-bit32.lua +++ b/tex/context/base/mkiv/l-bit32.lua @@ -141,8 +141,10 @@ else -- hope for the best or fail - bit32 = require("bit32") + -- bit32 = require("bit32") + + xpcall(function() local _, t = require("bit32") if t then bit32 = t end return end,function() end) end -return bit32 +return bit32 or false diff --git a/tex/context/base/mkiv/l-file.lua b/tex/context/base/mkiv/l-file.lua index c04883d8b..5fec0040f 100644 --- a/tex/context/base/mkiv/l-file.lua +++ b/tex/context/base/mkiv/l-file.lua @@ -703,3 +703,25 @@ function lfs.mkdirs(path) lfs.mkdir(full) end end + +-- here is oen i ran into when messign around with xavante code (keppler project) +-- where it's called in_base .. no gain in using lpeg here + +function file.withinbase(path) -- don't go beyond root + local l = 0 + if not find(path,"^/") then + path = "/" .. path + end + for dir in gmatch(path,"/([^/]+)") do + if dir == ".." then + l = l - 1 + elseif dir ~= "." then + l = l + 1 + end + if l < 0 then + return false + end + end + return true +end + diff --git a/tex/context/base/mkiv/l-lua.lua b/tex/context/base/mkiv/l-lua.lua index 0bbe958a4..b36bde422 100644 --- a/tex/context/base/mkiv/l-lua.lua +++ b/tex/context/base/mkiv/l-lua.lua @@ -230,7 +230,20 @@ elseif not ffi.number then ffi.number = tonumber end -if not bit32 and utf8 then +if not bit32 then -- and utf8 then -- bit32 = load ( [[ -- replacement code with 5.3 syntax so that 5.2 doesn't bark on it ]] ) bit32 = require("l-bit32") end + +-- We need this due a bug in luatex socket loading: + +local loaded = package.loaded + +if not loaded["socket"] then loaded["socket"] = loaded["socket.core"] end +if not loaded["mime"] then loaded["mime"] = loaded["mime.core"] end + +if not loaded["socket.http"] then loaded["socket.http"] = socket.http end +if not loaded["socket.ftp"] then loaded["socket.ftp"] = socket.ftp end +if not loaded["socket.smtp"] then loaded["socket.smtp"] = socket.smtp end +if not loaded["socket.tp"] then loaded["socket.tp"] = socket.tp end +if not loaded["socket.url"] then loaded["socket.url"] = socket.url end diff --git a/tex/context/base/mkiv/l-sandbox.lua b/tex/context/base/mkiv/l-sandbox.lua index 7a89aa8cd..2ecec0023 100644 --- a/tex/context/base/mkiv/l-sandbox.lua +++ b/tex/context/base/mkiv/l-sandbox.lua @@ -17,7 +17,7 @@ local global = _G local next = next local unpack = unpack or table.unpack local type = type -local tprint = texio.write_nl or print +local tprint = texio and texio.write_nl or print local tostring = tostring local format = string.format -- no formatters yet local concat = table.concat @@ -310,3 +310,4 @@ if supported("lfs") then lfs.shortname = register(lfs.shortname, "lfs.shortname") lfs.symlinkattributes = register(lfs.symlinkattributes,"lfs.symlinkattributes") end + diff --git a/tex/context/base/mkiv/l-table.lua b/tex/context/base/mkiv/l-table.lua index ba8712ddb..9d7152544 100644 --- a/tex/context/base/mkiv/l-table.lua +++ b/tex/context/base/mkiv/l-table.lua @@ -22,6 +22,10 @@ local floor = math.floor local stripper = patterns.stripper +function table.getn(t) + return t and #t -- for very old times sake +end + function table.strip(tab) local lst, l = { }, 0 for i=1,#tab do diff --git a/tex/context/base/mkiv/l-unicode.lua b/tex/context/base/mkiv/l-unicode.lua index 60a8cc006..b5f52d312 100644 --- a/tex/context/base/mkiv/l-unicode.lua +++ b/tex/context/base/mkiv/l-unicode.lua @@ -6,6 +6,9 @@ if not modules then modules = { } end modules ['l-unicode'] = { license = "see context related readme files" } +-- floor(b/256) => rshift(b, 8) +-- floor(b/1024) => rshift(b,10) + -- in lua 5.3: -- utf8.char(···) : concatinated @@ -40,8 +43,6 @@ local type = type local char, byte, format, sub, gmatch = string.char, string.byte, string.format, string.sub, string.gmatch local concat = table.concat local P, C, R, Cs, Ct, Cmt, Cc, Carg, Cp = lpeg.P, lpeg.C, lpeg.R, lpeg.Cs, lpeg.Ct, lpeg.Cmt, lpeg.Cc, lpeg.Carg, lpeg.Cp -local floor = math.floor -local rshift = bit32.rshift local lpegmatch = lpeg.match local patterns = lpeg.patterns @@ -80,56 +81,77 @@ if not utf.char then local char = string.char - function utf.char(n) - if n < 0x80 then - -- 0aaaaaaa : 0x80 - return char(n) - elseif n < 0x800 then - -- 110bbbaa : 0xC0 : n >> 6 - -- 10aaaaaa : 0x80 : n & 0x3F --- return char( --- 0xC0 + floor(n/0x40), --- 0x80 + (n % 0x40) --- ) - return char( - 0xC0 + rshift(n,6), - 0x80 + (n % 0x40) - ) - elseif n < 0x10000 then - -- 1110bbbb : 0xE0 : n >> 12 - -- 10bbbbaa : 0x80 : (n >> 6) & 0x3F - -- 10aaaaaa : 0x80 : n & 0x3F --- return char( --- 0xE0 + floor(n/0x1000), --- 0x80 + (floor(n/0x40) % 0x40), --- 0x80 + (n % 0x40) --- ) - return char( - 0xE0 + rshift(n,12), - 0x80 + (rshift(n,6) % 0x40), - 0x80 + (n % 0x40) - ) - elseif n < 0x200000 then - -- 11110ccc : 0xF0 : n >> 18 - -- 10ccbbbb : 0x80 : (n >> 12) & 0x3F - -- 10bbbbaa : 0x80 : (n >> 6) & 0x3F - -- 10aaaaaa : 0x80 : n & 0x3F - -- dddd : ccccc - 1 --- return char( --- 0xF0 + floor(n/0x40000), --- 0x80 + (floor(n/0x1000) % 0x40), --- 0x80 + (floor(n/0x40) % 0x40), --- 0x80 + (n % 0x40) --- ) - return char( - 0xF0 + rshift(n,18), - 0x80 + (rshift(n,12) % 0x40), - 0x80 + (rshift(n,6) % 0x40), - 0x80 + (n % 0x40) - ) - else - return "" + if bit32 then + + local rshift = bit32.rshift + + function utf.char(n) + if n < 0x80 then + -- 0aaaaaaa : 0x80 + return char(n) + elseif n < 0x800 then + -- 110bbbaa : 0xC0 : n >> 6 + -- 10aaaaaa : 0x80 : n & 0x3F + return char( + 0xC0 + rshift(n,6), + 0x80 + (n % 0x40) + ) + elseif n < 0x10000 then + -- 1110bbbb : 0xE0 : n >> 12 + -- 10bbbbaa : 0x80 : (n >> 6) & 0x3F + -- 10aaaaaa : 0x80 : n & 0x3F + return char( + 0xE0 + rshift(n,12), + 0x80 + (rshift(n,6) % 0x40), + 0x80 + (n % 0x40) + ) + elseif n < 0x200000 then + -- 11110ccc : 0xF0 : n >> 18 + -- 10ccbbbb : 0x80 : (n >> 12) & 0x3F + -- 10bbbbaa : 0x80 : (n >> 6) & 0x3F + -- 10aaaaaa : 0x80 : n & 0x3F + -- dddd : ccccc - 1 + return char( + 0xF0 + rshift(n,18), + 0x80 + (rshift(n,12) % 0x40), + 0x80 + (rshift(n,6) % 0x40), + 0x80 + (n % 0x40) + ) + else + return "" + end end + + else + + local floor = math.floor + + function utf.char(n) + if n < 0x80 then + return char(n) + elseif n < 0x800 then + return char( + 0xC0 + floor(n/0x40), + 0x80 + (n % 0x40) + ) + elseif n < 0x10000 then + return char( + 0xE0 + floor(n/0x1000), + 0x80 + (floor(n/0x40) % 0x40), + 0x80 + (n % 0x40) + ) + elseif n < 0x200000 then + return char( + 0xF0 + floor(n/0x40000), + 0x80 + (floor(n/0x1000) % 0x40), + 0x80 + (floor(n/0x40) % 0x40), + 0x80 + (n % 0x40) + ) + else + return "" + end + end + end end @@ -1045,9 +1067,6 @@ function utf.utf32_to_utf8_t(t,endian) return endian and utf32_to_utf8_be_t(t) or utf32_to_utf8_le_t(t) or t end --- floor(b/256) => rshift(b, 8) --- floor(b/1024) => rshift(b,10) - local function little(b) if b < 0x10000 then return char(b%256,rshift(b,8)) @@ -1286,32 +1305,36 @@ end -- -- local utf32 = table.setmetatableindex(function(t,k) local v = toutf32(k) t[k] = v return v end) -local extract = bit32.extract -local char = string.char - -function unicode.toutf32string(n) - if n <= 0xFF then - return - char(n) .. - "\000\000\000" - elseif n <= 0xFFFF then - return - char(extract(n, 0,8)) .. - char(extract(n, 8,8)) .. - "\000\000" - elseif n <= 0xFFFFFF then - return - char(extract(n, 0,8)) .. - char(extract(n, 8,8)) .. - char(extract(n,16,8)) .. - "\000" - else - return - char(extract(n, 0,8)) .. - char(extract(n, 8,8)) .. - char(extract(n,16,8)) .. - char(extract(n,24,8)) +if bit32 then + + local extract = bit32.extract + local char = string.char + + function unicode.toutf32string(n) + if n <= 0xFF then + return + char(n) .. + "\000\000\000" + elseif n <= 0xFFFF then + return + char(extract(n, 0,8)) .. + char(extract(n, 8,8)) .. + "\000\000" + elseif n <= 0xFFFFFF then + return + char(extract(n, 0,8)) .. + char(extract(n, 8,8)) .. + char(extract(n,16,8)) .. + "\000" + else + return + char(extract(n, 0,8)) .. + char(extract(n, 8,8)) .. + char(extract(n,16,8)) .. + char(extract(n,24,8)) + end end + end -- goodie: diff --git a/tex/context/base/mkiv/l-url.lua b/tex/context/base/mkiv/l-url.lua index bc407a84d..6f834d778 100644 --- a/tex/context/base/mkiv/l-url.lua +++ b/tex/context/base/mkiv/l-url.lua @@ -11,6 +11,7 @@ local concat = table.concat local tonumber, type, next = tonumber, type, next local P, C, R, S, Cs, Cc, Ct, Cf, Cg, V = lpeg.P, lpeg.C, lpeg.R, lpeg.S, lpeg.Cs, lpeg.Cc, lpeg.Ct, lpeg.Cf, lpeg.Cg, lpeg.V local lpegmatch, lpegpatterns, replacer = lpeg.match, lpeg.patterns, lpeg.replacer +local sortedhash = table.sortedhash -- from wikipedia: -- @@ -32,22 +33,61 @@ local lpegmatch, lpegpatterns, replacer = lpeg.match, lpeg.patterns, lpeg.replac url = url or { } local url = url -local tochar = function(s) return char(tonumber(s,16)) end +local unescapes = { } +local escapes = { } + +setmetatable(unescapes, { __index = function(t,k) + local v = char(tonumber(k,16)) + t[k] = v + return v +end }) + +setmetatable(escapes, { __index = function(t,k) + local v = format("%%%02X",byte(k)) + t[k] = v + return v +end }) + +-- okay: local colon = P(":") local qmark = P("?") local hash = P("#") local slash = P("/") +local atsign = P("@") local percent = P("%") local endofstring = P(-1) - local hexdigit = R("09","AF","af") local plus = P("+") local nothing = Cc("") -local escapedchar = (percent * C(hexdigit * hexdigit)) / tochar -local escaped = (plus / " ") + escapedchar -- so no loc://foo++.tex - -local noslash = P("/") / "" +local okay = R("09","AZ","az") + S("-_.,:=+*~!'()@&$") + +local escapedchar = (percent * C(hexdigit * hexdigit)) / unescapes +local unescapedchar = P(1) / escapes +local escaped = (plus / " ") + escapedchar -- so no loc://foo++.tex +local noslash = P("/") / "" +local plustospace = P("+")/" " + +local decoder = Cs( ( + plustospace + + escapedchar + + P("\r\n")/"\n" + + P(1) + )^0 ) +local encoder = Cs( ( + R("09","AZ","az")^1 + + S("-./_")^1 + + P(" ")/"+" + + P("\n")/"\r\n" + + unescapedchar + )^0 ) + +lpegpatterns.urldecoder = decoder +lpegpatterns.urlencoder = encoder + +function url.decode (str) return str and lpegmatch(decoder, str) or str end +function url.encode (str) return str and lpegmatch(encoder, str) or str end +function url.unescape(str) return str and lpegmatch(unescaper,str) or str end -- we assume schemes with more than 1 character (in order to avoid problems with windows disks) -- we also assume that when we have a scheme, we also have an authority @@ -73,17 +113,9 @@ local parser = Ct(validurl) lpegpatterns.url = validurl lpegpatterns.urlsplitter = parser -local escapes = { } - -setmetatable(escapes, { __index = function(t,k) - local v = format("%%%02X",byte(k)) - t[k] = v - return v -end }) - -local escaper = Cs((R("09","AZ","az")^1 + P(" ")/"%%20" + S("-./_")^1 + P(1) / escapes)^0) -- space happens most +local escaper = Cs((R("09","AZ","az")^1 + P(" ")/"%%20" + S("-./_:")^1 + P(1) / escapes)^0) -- space happens most local unescaper = Cs((escapedchar + 1)^0) -local getcleaner = Cs((P("+++") / "%%2B" + P("+") / "%%20" + P(1))^1) +local getcleaner = Cs((P("+++")/"%%2B" + P("+")/"%%20" + P(1))^1) lpegpatterns.urlunescaped = escapedchar lpegpatterns.urlescaper = escaper @@ -134,8 +166,8 @@ local backslashswapper = replacer("\\","/") local equal = P("=") local amp = P("&") -local key = Cs(((escapedchar+1)-equal )^0) -local value = Cs(((escapedchar+1)-amp -endofstring)^0) +local key = Cs(((plustospace + escapedchar + 1) - equal )^0) +local value = Cs(((plustospace + escapedchar + 1) - amp - endofstring)^0) local splitquery = Cf ( Ct("") * P { "sequence", sequence = V("pair") * (amp * V("pair"))^0, @@ -144,6 +176,11 @@ local splitquery = Cf ( Ct("") * P { "sequence", -- hasher +local userpart = (1-atsign-colon)^1 +local serverpart = (1-colon)^1 +local splitauthority = ((Cs(userpart) * colon * Cs(userpart) + Cs(userpart) * Cc(nil)) * atsign + Cc(nil) * Cc(nil)) + * Cs(serverpart) * (colon * (serverpart/tonumber) + Cc(nil)) + local function hashed(str) -- not yet ok (/test?test) if not str or str == "" then return { @@ -177,12 +214,21 @@ local function hashed(str) -- not yet ok (/test?test) -- not always a filename but handy anyway local authority = detailed[2] local path = detailed[3] - local filename = nil + local filename -- = nil + local username -- = nil + local password -- = nil + local host -- = nil + local port -- = nil + if authority ~= "" then + -- these can be invalid + username, password, host, port = lpegmatch(splitauthority,authority) + end if authority == "" then filename = path elseif path == "" then filename = "" else + -- this one can be can be invalid filename = authority .. "/" .. path end return { @@ -195,6 +241,11 @@ local function hashed(str) -- not yet ok (/test?test) original = str, noscheme = false, filename = filename, + -- + host = host, + port = port, + -- usename = username, + -- password = password, } end @@ -236,24 +287,38 @@ function url.addscheme(str,scheme) -- no authority end function url.construct(hash) -- dodo: we need to escape ! - local fullurl, f = { }, 0 - local scheme, authority, path, query, fragment = hash.scheme, hash.authority, hash.path, hash.query, hash.fragment + local result, r = { }, 0 + local scheme = hash.scheme + local authority = hash.authority + local path = hash.path + local queries = hash.queries + local fragment = hash.fragment if scheme and scheme ~= "" then - f = f + 1 ; fullurl[f] = scheme .. "://" + r = r + 1 ; result[r] = lpegmatch(escaper,scheme) + r = r + 1 ; result[r] = "://" end if authority and authority ~= "" then - f = f + 1 ; fullurl[f] = authority + r = r + 1 ; result[r] = lpegmatch(escaper,authority) end if path and path ~= "" then - f = f + 1 ; fullurl[f] = "/" .. path + r = r + 1 ; result[r] = "/" + r = r + 1 ; result[r] = lpegmatch(escaper,path) end - if query and query ~= "" then - f = f + 1 ; fullurl[f] = "?".. query + if queries then + local done = false + for k, v in sortedhash(queries) do + r = r + 1 ; result[r] = done and "&" or "?" + r = r + 1 ; result[r] = lpegmatch(escaper,k) -- is this escaped + r = r + 1 ; result[r] = "=" + r = r + 1 ; result[r] = lpegmatch(escaper,v) -- is this escaped + done = true + end end if fragment and fragment ~= "" then - f = f + 1 ; fullurl[f] = "#".. fragment + r = r + 1 ; result[r] = "#" + r = r + 1 ; result[r] = lpegmatch(escaper,fragment) end - return lpegmatch(escaper,concat(fullurl)) + return concat(result) end local pattern = Cs(slash^-1/"" * R("az","AZ") * ((S(":|")/":") + P(":")) * slash * P(1)^0) diff --git a/tex/context/base/mkiv/lpdf-epd.lua b/tex/context/base/mkiv/lpdf-epd.lua index 48d63bab4..2fcd28473 100644 --- a/tex/context/base/mkiv/lpdf-epd.lua +++ b/tex/context/base/mkiv/lpdf-epd.lua @@ -873,7 +873,7 @@ function lpdf_epdf.contenttotext(document,list) -- maybe signal fonts local dy = abs(last_y - ty) if dy > linefactor*last_f then if last > 0 then - if find(text[last],softhyphen) then + if find(text[last],softhyphen,1,true) then -- ignore else last = last + 1 diff --git a/tex/context/base/mkiv/lpdf-mis.lua b/tex/context/base/mkiv/lpdf-mis.lua index 4ccbd0e4f..07dc3dcf1 100644 --- a/tex/context/base/mkiv/lpdf-mis.lua +++ b/tex/context/base/mkiv/lpdf-mis.lua @@ -448,10 +448,13 @@ local function documentspecification() local marked = pages.allmarked(marked) local nofmarked = marked and #marked or 0 if nofmarked > 0 then + -- the spec is wrong in saying that numbering starts at 1 which of course makes + -- sense as most real documents start with page 0 .. sigh + for i=1,#marked do marked[i] = marked[i] - 1 end prints = pdfarray(flattened(pages.toranges(marked))) end end - if fit or fixed or duplex or copies or paper or marked then + if fit or fixed or duplex or copies or paper or prints then addtocatalog("ViewerPreferences",pdfdictionary { FitWindow = fit and true or nil, PrintScaling = fixed and pdfconstant("None") or nil, diff --git a/tex/context/base/mkiv/luat-cod.lua b/tex/context/base/mkiv/luat-cod.lua index 5a2dc30cc..91bb7c2e1 100644 --- a/tex/context/base/mkiv/luat-cod.lua +++ b/tex/context/base/mkiv/luat-cod.lua @@ -119,7 +119,7 @@ local targetpath = "." if LUATEXENGINE == nil then LUATEXENGINE = status.luatex_engine and string.lower(status.luatex_engine) - or (find(status.banner,"LuajitTeX") and "luajittex" or "luatex") + or (find(status.banner,"LuajitTeX",1,true) and "luajittex" or "luatex") end if LUATEXVERION == nil then diff --git a/tex/context/base/mkiv/luat-ini.lua b/tex/context/base/mkiv/luat-ini.lua index 83b7717a4..de7254922 100644 --- a/tex/context/base/mkiv/luat-ini.lua +++ b/tex/context/base/mkiv/luat-ini.lua @@ -29,7 +29,7 @@ LUATEXVERSION = status.luatex_version/100 + tonumber(status.luatex_revision)/1000 LUATEXENGINE = status.luatex_engine and string.lower(status.luatex_engine) - or (string.find(status.banner,"LuajitTeX") and "luajittex" or "luatex") + or (string.find(status.banner,"LuajitTeX",1,true) and "luajittex" or "luatex") JITSUPPORTED = LUATEXENGINE == "luajittex" or jit diff --git a/tex/context/base/mkiv/luat-run.lua b/tex/context/base/mkiv/luat-run.lua index 2c3ba0b4d..59fb0b937 100644 --- a/tex/context/base/mkiv/luat-run.lua +++ b/tex/context/base/mkiv/luat-run.lua @@ -207,7 +207,7 @@ local function report_start(left,name) -- report_load("%s > %s",types[left],name or "?") report_load("type %a, name %a",types[left],name or "?") end - elseif find(name,"virtual://") then + elseif find(name,"virtual://",1,true) then insert(stack,false) else insert(stack,name) diff --git a/tex/context/base/mkiv/lxml-css.lua b/tex/context/base/mkiv/lxml-css.lua index b2198f341..bc6297ac2 100644 --- a/tex/context/base/mkiv/lxml-css.lua +++ b/tex/context/base/mkiv/lxml-css.lua @@ -332,12 +332,12 @@ local function s_attribute(list,collected,c,negate,str,what,value) end elseif what == 2 then -- todo: lpeg - if find(v,value) then + if find(v,value) then -- value can be a pattern ok = not negate end elseif what == 3 then -- todo: lpeg - if find(v," ") then + if find(v," ",1,true) then for s in gmatch(v,"[^ ]+") do if s == value then ok = not negate diff --git a/tex/context/base/mkiv/lxml-tex.lua b/tex/context/base/mkiv/lxml-tex.lua index 736df7ce2..1413159ec 100644 --- a/tex/context/base/mkiv/lxml-tex.lua +++ b/tex/context/base/mkiv/lxml-tex.lua @@ -1443,7 +1443,7 @@ end local function command(collected,cmd,otherwise) local n = collected and #collected if n and n > 0 then - local wildcard = find(cmd,"%*") + local wildcard = find(cmd,"*",1,true) for c=1,n do -- maybe optimize for n=1 local e = collected[c] local ix = e.ix @@ -1467,7 +1467,7 @@ end -- local wildcards = setmetatableindex(function(t,k) -- local v = false --- if find(k,"%*") then +-- if find(k,"*",1,true) then -- v = setmetatableindex(function(t,kk) -- local v = gsub(k,"%*",kk) -- t[k] = v diff --git a/tex/context/base/mkiv/meta-pdf.lua b/tex/context/base/mkiv/meta-pdf.lua index 10a089b9e..4a185cebd 100644 --- a/tex/context/base/mkiv/meta-pdf.lua +++ b/tex/context/base/mkiv/meta-pdf.lua @@ -531,7 +531,7 @@ local captures_old = ( space + verbose + preamble )^0 local captures_new = ( space + verbose + procset + preamble )^0 local function parse(m_data) - if find(m_data,"%%%%BeginResource: procset mpost") then + if find(m_data,"%%BeginResource: procset mpost",1,true) then -- report_mptopdf("using sparse scanner, case 1") lpegmatch(captures_new,m_data) elseif find(m_data,"%%%%BeginProlog%s*%S+(.-)%%%%EndProlog") then diff --git a/tex/context/base/mkiv/meta-pdh.lua b/tex/context/base/mkiv/meta-pdh.lua index 2d58c64dd..afd1576cb 100644 --- a/tex/context/base/mkiv/meta-pdh.lua +++ b/tex/context/base/mkiv/meta-pdh.lua @@ -100,7 +100,7 @@ function mptopdf.steps.strip() -- .3 per expr end local name, version = gmatch(preamble,"%%%%Creator: +(.-) +(.-) ") mptopdf.version = tostring(version or "0") - if find(preamble,"/hlw{0 dtransform") then + if find(preamble,"/hlw{0 dtransform",1,true) then mptopdf.shortcuts = true end -- the boundingbox specification needs to come before data, well, not really @@ -589,7 +589,7 @@ do local captures_new = ( space + procset + preamble + verbose )^0 function mptopdf.parsers.lpeg() - if find(mptopdf.data,"%%%%BeginResource: procset mpost") then + if find(mptopdf.data,"%%BeginResource: procset mpost",1,true) then lpegmatch(captures_new,mptopdf.data) else lpegmatch(captures_old,mptopdf.data) diff --git a/tex/context/base/mkiv/mlib-lua.lua b/tex/context/base/mkiv/mlib-lua.lua index 7efed1e5d..5e6be614b 100644 --- a/tex/context/base/mkiv/mlib-lua.lua +++ b/tex/context/base/mkiv/mlib-lua.lua @@ -242,7 +242,7 @@ local replacer = lpeg.replacer("@","%%") function mp.fprint(fmt,...) n = n + 1 - if not find(fmt,"%%") then + if not find(fmt,"%",1,true) then fmt = lpegmatch(replacer,fmt) end buffer[n] = formatters[fmt](...) @@ -251,7 +251,7 @@ end local function mpquoted(fmt,s,...) n = n + 1 if s then - if not find(fmt,"%%") then + if not find(fmt,"%",1,true) then fmt = lpegmatch(replacer,fmt) end -- buffer[n] = '"' .. formatters[fmt](s,...) .. '"' diff --git a/tex/context/base/mkiv/mtx-context-module.tex b/tex/context/base/mkiv/mtx-context-module.tex index d754f5305..f8b6d0a54 100644 --- a/tex/context/base/mkiv/mtx-context-module.tex +++ b/tex/context/base/mkiv/mtx-context-module.tex @@ -22,7 +22,7 @@ \input mtx-context-common.tex \usemodule[scite] -\usemodule[modules-basics] +\usemodule[module-basic] \dontcomplain diff --git a/tex/context/base/mkiv/mult-low.lua b/tex/context/base/mkiv/mult-low.lua index 50ddeff2c..84b4189dc 100644 --- a/tex/context/base/mkiv/mult-low.lua +++ b/tex/context/base/mkiv/mult-low.lua @@ -278,7 +278,7 @@ return { "singleexpandafter", "doubleexpandafter", "tripleexpandafter", -- "dontleavehmode", "removelastspace", "removeunwantedspaces", "keepunwantedspaces", - "removepunctuation", "ignoreparskip", + "removepunctuation", "ignoreparskip", "forcestrutdepth", -- "wait", "writestatus", "define", "defineexpandable", "redefine", -- diff --git a/tex/context/base/mkiv/page-ini.lua b/tex/context/base/mkiv/page-ini.lua index a02bbc892..17723c421 100644 --- a/tex/context/base/mkiv/page-ini.lua +++ b/tex/context/base/mkiv/page-ini.lua @@ -41,7 +41,10 @@ function pages.mark(name,list) local page = list[i] local sign = false if type(page) == "string" then - sign, page = match(page,"([%+%-])(%d+)") + local s, p = match(page,"([%+%-])(%d+)") + if s then + sign, page = s, p + end end page = tonumber(page) if page then diff --git a/tex/context/base/mkiv/publ-dat.lua b/tex/context/base/mkiv/publ-dat.lua index fce69b158..310df82f3 100644 --- a/tex/context/base/mkiv/publ-dat.lua +++ b/tex/context/base/mkiv/publ-dat.lua @@ -323,7 +323,7 @@ end function publications.parenttag(dataset,tag) if not dataset or not tag then report("error in specification, dataset %a, tag %a",dataset,tag) - elseif find(tag,"%+") then + elseif find(tag,"+",1,true) then local tags = lpegmatch(p_splitter,tag) local parent = tags[1] local current = datasets[dataset] diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex 4b3857135..1693e5e85 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex fea1f2b83..f63b33d65 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/supp-box.mkiv b/tex/context/base/mkiv/supp-box.mkiv index d187518fe..fb9cbdf5d 100644 --- a/tex/context/base/mkiv/supp-box.mkiv +++ b/tex/context/base/mkiv/supp-box.mkiv @@ -2967,7 +2967,7 @@ %D Who knows when this comes in handy: -\unexpanded\def\lastlinewidth{\dimexpr\clf_lastlinelength\scaledpoint\relax} +\unexpanded\def\lastlinewidth{\dimexpr\clf_lastlinewidth\scaledpoint\relax} %D Keep as reference: diff --git a/tex/context/base/mkiv/syst-aux.lua b/tex/context/base/mkiv/syst-aux.lua index f88938686..06f6176b1 100644 --- a/tex/context/base/mkiv/syst-aux.lua +++ b/tex/context/base/mkiv/syst-aux.lua @@ -390,8 +390,8 @@ local function doifelsecommon(a,b) end return end - local ba = find(a,",") - local bb = find(b,",") + local ba = find(a,",",1,true) + local bb = find(b,",",1,true) if ba and bb then local ha = hash[a] local hb = hash[b] @@ -433,8 +433,8 @@ local function doifcommon(a,b) end return end - local ba = find(a,",") - local bb = find(b,",") + local ba = find(a,",",1,true) + local bb = find(b,",",1,true) if ba and bb then local ha = hash[a] local hb = hash[b] @@ -476,8 +476,8 @@ local function doifnotcommon(a,b) end return end - local ba = find(a,",") - local bb = find(b,",") + local ba = find(a,",",1,true) + local bb = find(b,",",1,true) if ba and bb then local ha = hash[a] local hb = hash[b] @@ -519,7 +519,7 @@ local function doifelseinset(a,b) end return end - local bb = find(b,",") + local bb = find(b,",",1,true) if bb then if hash[b][a] then -- if settings_to_set(b)[a] then @@ -542,7 +542,7 @@ local function doifinset(a,b) end return end - local bb = find(b,",") + local bb = find(b,",",1,true) if bb then if hash[b][a] then -- if settings_to_set(b)[a] then @@ -565,7 +565,7 @@ local function doifnotinset(a,b) end return end - local bb = find(b,",") + local bb = find(b,",",1,true) if bb then if hash[b][a] then -- if settings_to_set(b)[a] then diff --git a/tex/context/base/mkiv/util-fil.lua b/tex/context/base/mkiv/util-fil.lua index b44dbc3fe..0e8ed4e57 100644 --- a/tex/context/base/mkiv/util-fil.lua +++ b/tex/context/base/mkiv/util-fil.lua @@ -6,11 +6,8 @@ if not modules then modules = { } end modules ['util-fil'] = { license = "see context related readme files" } -local byte = string.byte -local char = string.char -local extract = bit32.extract -local rshift = bit32.rshift -local band = bit32.band +local byte = string.byte +local char = string.char -- Here are a few helpers (the starting point were old ones I used for parsing -- flac files). In Lua 5.3 we can probably do this better. Some code will move @@ -239,15 +236,22 @@ end -- (real) ((n<<16)>>(16+14)) + ((n&0x3fff)/16384.0)) -function files.read2dot14(f) - local a, b = byte(f:read(2),1,2) - if a >= 0x80 then - local n = -(0x100 * a + b) - return - (extract(n,14,2) + (band(n,0x3FFF) / 16384.0)) - else - local n = 0x100 * a + b - return (extract(n,14,2) + (band(n,0x3FFF) / 16384.0)) +if bit32 then + + local extract = bit32.extract + local band = bit32.band + + function files.read2dot14(f) + local a, b = byte(f:read(2),1,2) + if a >= 0x80 then + local n = -(0x100 * a + b) + return - (extract(n,14,2) + (band(n,0x3FFF) / 16384.0)) + else + local n = 0x100 * a + b + return (extract(n,14,2) + (band(n,0x3FFF) / 16384.0)) + end end + end function files.skipshort(f,n) @@ -260,11 +264,28 @@ end -- writers (kind of slow) -function files.writecardinal2(f,n) - local a = char(n % 256) - n = rshift(n,8) - local b = char(n % 256) - f:write(b,a) +if bit32 then + + local rshift = bit32.rshift + + function files.writecardinal2(f,n) + local a = char(n % 256) + n = rshift(n,8) + local b = char(n % 256) + f:write(b,a) + end + +else + + local floor = math.floor + + function files.writecardinal2(f,n) + local a = char(n % 256) + n = floor(n/256) + local b = char(n % 256) + f:write(b,a) + end + end function files.writecardinal4(f,n) diff --git a/tex/context/base/mkiv/util-sbx.lua b/tex/context/base/mkiv/util-sbx.lua index 9318ee38a..57c576870 100644 --- a/tex/context/base/mkiv/util-sbx.lua +++ b/tex/context/base/mkiv/util-sbx.lua @@ -462,7 +462,7 @@ function sandbox.getrunner(name) end local function suspicious(str) - return (find(str,"[/\\]") or find(command,"%.%.")) and true or false + return (find(str,"[/\\]") or find(command,"..",1,true)) and true or false end local function binaryrunner(action,command,...) diff --git a/tex/context/base/mkiv/util-sci.lua b/tex/context/base/mkiv/util-sci.lua index 35385a183..fe28635a3 100644 --- a/tex/context/base/mkiv/util-sci.lua +++ b/tex/context/base/mkiv/util-sci.lua @@ -125,7 +125,7 @@ end local function exportwhites() return setmetatableindex(function(t,k) - local v = find(k,"white") and true or false + local v = find(k,"white",1,true) and true or false t[k] = v return v end) diff --git a/tex/context/base/mkiv/util-sql-imp-ffi.lua b/tex/context/base/mkiv/util-sql-imp-ffi.lua index 213fce18e..adda02107 100644 --- a/tex/context/base/mkiv/util-sql-imp-ffi.lua +++ b/tex/context/base/mkiv/util-sql-imp-ffi.lua @@ -146,6 +146,10 @@ local sql = utilities.sql ----- mysql = ffi.load(os.name == "windows" and "libmysql" or "libmysqlclient") local mysql = ffilib(os.name == "windows" and "libmysql" or "libmysqlclient") +if not mysql then + report_state("unable to load library") +end + local nofretries = 5 local retrydelay = 1 @@ -516,6 +520,8 @@ local tostring = tostring local tonumber = tonumber local booleanstring = string.booleanstring +local NULL = ffi.cast("MYSQL_result *",0) + %s return function(result) @@ -533,7 +539,12 @@ return function(result) local cells = { } local row = mysql_fetch_row(_result_) for j=1,noffields do - cells[j] = ffi_tostring(row[j-1]) + local s = row[j-1] + if s == NULL then + cells[j] = "" + else + cells[j] = ffi_tostring(s) + end end target[%s] = { %s diff --git a/tex/context/interface/mkii/keys-pe.xml b/tex/context/interface/mkii/keys-pe.xml index 486c8f530..e587e1d6e 100644 --- a/tex/context/interface/mkii/keys-pe.xml +++ b/tex/context/interface/mkii/keys-pe.xml @@ -1083,6 +1083,7 @@ <cd:constant name='preview' value='پیشدید'/> <cd:constant name='previous' value='قبلی'/> <cd:constant name='previousnumber' value='شمارهقبلی'/> + <cd:constant name='print' value='print'/> <cd:constant name='printable' value='قابلچاپ'/> <cd:constant name='process' value='پردازش'/> <cd:constant name='profile' value='profile'/> diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf Binary files differindex ae9a39d06..1a29d501f 100644 --- a/tex/context/interface/mkiv/i-context.pdf +++ b/tex/context/interface/mkiv/i-context.pdf diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf Binary files differindex 95cb45722..47eb69524 100644 --- a/tex/context/interface/mkiv/i-readme.pdf +++ b/tex/context/interface/mkiv/i-readme.pdf diff --git a/tex/context/modules/common/s-mod.ctx b/tex/context/modules/common/s-mod.ctx index 3a086d0ba..0560c6cfb 100644 --- a/tex/context/modules/common/s-mod.ctx +++ b/tex/context/modules/common/s-mod.ctx @@ -17,7 +17,7 @@ </ctx:flags> <ctx:process> <ctx:resources> - <ctx:module>modules-basics</ctx:module> + <ctx:module>module-basic</ctx:module> </ctx:resources> </ctx:process> </ctx:job> diff --git a/tex/context/modules/mkiv/s-domotica-settings.lua b/tex/context/modules/mkiv/s-domotica-settings.lua index a564ddf0e..c7946666d 100644 --- a/tex/context/modules/mkiv/s-domotica-settings.lua +++ b/tex/context/modules/mkiv/s-domotica-settings.lua @@ -48,7 +48,7 @@ function moduledata.zwave.show_settings(pattern) end - if string.find(pattern,"%*") then + if string.find(pattern,"*",1,true) then local list = dir.glob(pattern) local last = nil diff --git a/tex/context/modules/mkiv/s-modules-basics.mkiv b/tex/context/modules/mkiv/s-module-basic.mkiv index 74621b2a3..74621b2a3 100644 --- a/tex/context/modules/mkiv/s-modules-basics.mkiv +++ b/tex/context/modules/mkiv/s-module-basic.mkiv diff --git a/tex/context/modules/mkiv/x-asciimath.lua b/tex/context/modules/mkiv/x-asciimath.lua index 02c2375d4..7785d5587 100644 --- a/tex/context/modules/mkiv/x-asciimath.lua +++ b/tex/context/modules/mkiv/x-asciimath.lua @@ -1291,7 +1291,7 @@ local function collapse_bars(t) local d = false for i=1,m do local ti = t[i] - if type(ti) == "string" and find(ti,"\\left") then + if type(ti) == "string" and find(ti,"\\left",1,true) then d = true break end diff --git a/tex/context/modules/mkiv/x-ct.lua b/tex/context/modules/mkiv/x-ct.lua index 9c647e8e7..d9d474825 100644 --- a/tex/context/modules/mkiv/x-ct.lua +++ b/tex/context/modules/mkiv/x-ct.lua @@ -37,7 +37,7 @@ local function roottemplate(root) if template then return template else - if not find(rt,"|") then + if not find(rt,"|",1,true) then rt = gsub(rt,",","|") end if not find(rt,"^|") then rt = "|" .. rt end diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index b741295b6..42f791da2 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 02/25/18 19:48:01 +-- merge date : 03/06/18 14:59:23 do -- begin closure to overcome local limits and interference @@ -120,9 +120,17 @@ if not FFISUPPORTED then elseif not ffi.number then ffi.number=tonumber end -if not bit32 and utf8 then +if not bit32 then bit32=require("l-bit32") end +local loaded=package.loaded +if not loaded["socket"] then loaded["socket"]=loaded["socket.core"] end +if not loaded["mime"] then loaded["mime"]=loaded["mime.core"] end +if not loaded["socket.http"] then loaded["socket.http"]=socket.http end +if not loaded["socket.ftp"] then loaded["socket.ftp"]=socket.ftp end +if not loaded["socket.smtp"] then loaded["socket.smtp"]=socket.smtp end +if not loaded["socket.tp"] then loaded["socket.tp"]=socket.tp end +if not loaded["socket.url"] then loaded["socket.url"]=socket.url end end -- closure @@ -1072,6 +1080,9 @@ local getinfo=debug.getinfo local lpegmatch,patterns=lpeg.match,lpeg.patterns local floor=math.floor local stripper=patterns.stripper +function table.getn(t) + return t and #t +end function table.strip(tab) local lst,l={},0 for i=1,#tab do @@ -2847,6 +2858,23 @@ function lfs.mkdirs(path) lfs.mkdir(full) end end +function file.withinbase(path) + local l=0 + if not find(path,"^/") then + path="/"..path + end + for dir in gmatch(path,"/([^/]+)") do + if dir==".." then + l=l-1 + elseif dir~="." then + l=l+1 + end + if l<0 then + return false + end + end + return true +end end -- closure @@ -3024,8 +3052,6 @@ local type=type local char,byte,format,sub,gmatch=string.char,string.byte,string.format,string.sub,string.gmatch local concat=table.concat local P,C,R,Cs,Ct,Cmt,Cc,Carg,Cp=lpeg.P,lpeg.C,lpeg.R,lpeg.Cs,lpeg.Ct,lpeg.Cmt,lpeg.Cc,lpeg.Carg,lpeg.Cp -local floor=math.floor -local rshift=bit32.rshift local lpegmatch=lpeg.match local patterns=lpeg.patterns local tabletopattern=lpeg.utfchartabletopattern @@ -3049,29 +3075,59 @@ if not utf.char then utf.char=string.utfcharacter or (utf8 and utf8.char) if not utf.char then local char=string.char - function utf.char(n) - if n<0x80 then - return char(n) - elseif n<0x800 then - return char( - 0xC0+rshift(n,6), - 0x80+(n%0x40) - ) - elseif n<0x10000 then - return char( - 0xE0+rshift(n,12), - 0x80+(rshift(n,6)%0x40), - 0x80+(n%0x40) - ) - elseif n<0x200000 then - return char( - 0xF0+rshift(n,18), - 0x80+(rshift(n,12)%0x40), - 0x80+(rshift(n,6)%0x40), - 0x80+(n%0x40) - ) - else - return "" + if bit32 then + local rshift=bit32.rshift + function utf.char(n) + if n<0x80 then + return char(n) + elseif n<0x800 then + return char( + 0xC0+rshift(n,6), + 0x80+(n%0x40) + ) + elseif n<0x10000 then + return char( + 0xE0+rshift(n,12), + 0x80+(rshift(n,6)%0x40), + 0x80+(n%0x40) + ) + elseif n<0x200000 then + return char( + 0xF0+rshift(n,18), + 0x80+(rshift(n,12)%0x40), + 0x80+(rshift(n,6)%0x40), + 0x80+(n%0x40) + ) + else + return "" + end + end + else + local floor=math.floor + function utf.char(n) + if n<0x80 then + return char(n) + elseif n<0x800 then + return char( + 0xC0+floor(n/0x40), + 0x80+(n%0x40) + ) + elseif n<0x10000 then + return char( + 0xE0+floor(n/0x1000), + 0x80+(floor(n/0x40)%0x40), + 0x80+(n%0x40) + ) + elseif n<0x200000 then + return char( + 0xF0+floor(n/0x40000), + 0x80+(floor(n/0x1000)%0x40), + 0x80+(floor(n/0x40)%0x40), + 0x80+(n%0x40) + ) + else + return "" + end end end end @@ -3632,21 +3688,23 @@ function utf.chrlen(u) (u<0xFC and 5) or (u<0xFE and 6) or 0 end -local extract=bit32.extract -local char=string.char -function unicode.toutf32string(n) - if n<=0xFF then - return - char(n).."\000\000\000" - elseif n<=0xFFFF then - return - char(extract(n,0,8))..char(extract(n,8,8)).."\000\000" - elseif n<=0xFFFFFF then - return - char(extract(n,0,8))..char(extract(n,8,8))..char(extract(n,16,8)).."\000" - else - return - char(extract(n,0,8))..char(extract(n,8,8))..char(extract(n,16,8))..char(extract(n,24,8)) +if bit32 then + local extract=bit32.extract + local char=string.char + function unicode.toutf32string(n) + if n<=0xFF then + return + char(n).."\000\000\000" + elseif n<=0xFFFF then + return + char(extract(n,0,8))..char(extract(n,8,8)).."\000\000" + elseif n<=0xFFFFFF then + return + char(extract(n,0,8))..char(extract(n,8,8))..char(extract(n,16,8)).."\000" + else + return + char(extract(n,0,8))..char(extract(n,8,8))..char(extract(n,16,8))..char(extract(n,24,8)) + end end end local len=utf.len @@ -4481,9 +4539,6 @@ if not modules then modules={} end modules ['util-fil']={ } local byte=string.byte local char=string.char -local extract=bit32.extract -local rshift=bit32.rshift -local band=bit32.band utilities=utilities or {} local files={} utilities.files=files @@ -4653,14 +4708,18 @@ function files.readfixed4(f) return (0x100*a+b )+(0x100*c+d)/0x10000 end end -function files.read2dot14(f) - local a,b=byte(f:read(2),1,2) - if a>=0x80 then - local n=-(0x100*a+b) - return-(extract(n,14,2)+(band(n,0x3FFF)/16384.0)) - else - local n=0x100*a+b - return (extract(n,14,2)+(band(n,0x3FFF)/16384.0)) +if bit32 then + local extract=bit32.extract + local band=bit32.band + function files.read2dot14(f) + local a,b=byte(f:read(2),1,2) + if a>=0x80 then + local n=-(0x100*a+b) + return-(extract(n,14,2)+(band(n,0x3FFF)/16384.0)) + else + local n=0x100*a+b + return (extract(n,14,2)+(band(n,0x3FFF)/16384.0)) + end end end function files.skipshort(f,n) @@ -4669,11 +4728,22 @@ end function files.skiplong(f,n) f:read(4*(n or 1)) end -function files.writecardinal2(f,n) - local a=char(n%256) - n=rshift(n,8) - local b=char(n%256) - f:write(b,a) +if bit32 then + local rshift=bit32.rshift + function files.writecardinal2(f,n) + local a=char(n%256) + n=rshift(n,8) + local b=char(n%256) + f:write(b,a) + end +else + local floor=math.floor + function files.writecardinal2(f,n) + local a=char(n%256) + n=floor(n/256) + local b=char(n%256) + f:write(b,a) + end end function files.writecardinal4(f,n) local a=char(n%256) @@ -7976,7 +8046,7 @@ local psfake=0 local function fixedpsname(psname,fallback) local usedname=psname if psname and psname~="" then - if find(psname," ") then + if find(psname," ",1,true) then usedname=gsub(psname,"[%s]+","-") else end @@ -30052,7 +30122,7 @@ do report_pfb("no data in %a",filename) return end - if not (find(data,"!PS%-AdobeFont%-") or find(data,"%%!FontType1")) then + if not (find(data,"!PS-AdobeFont-",1,true) or find(data,"%!FontType1",1,true)) then report_pfb("no font in %a",filename) return end |