diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3kernel/expl3.lua')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3kernel/expl3.lua | 119 |
1 files changed, 105 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/latex/l3kernel/expl3.lua b/Master/texmf-dist/tex/latex/l3kernel/expl3.lua index 1da6f623d37..ca496b495c9 100644 --- a/Master/texmf-dist/tex/latex/l3kernel/expl3.lua +++ b/Master/texmf-dist/tex/latex/l3kernel/expl3.lua @@ -20,23 +20,114 @@ -- -- File: l3luatex.dtx Copyright (C) 2010-2017 The LaTeX3 Project l3kernel = l3kernel or { } -local tex_setcatcode = tex.setcatcode -local tex_sprint = tex.sprint -local tex_write = tex.write -local unicode_utf8_char = unicode.utf8.char -local function strcmp (A, B) +local io = io +local kpse = kpse +local lfs = lfs +local math = math +local md5 = md5 +local os = os +local string = string +local tex = tex +local unicode = unicode +local abs = math.abs +local byte = string.byte +local floor = math.floor +local format = string.format +local gsub = string.gsub +local kpse_find = kpse.find_file +local lfs_attr = lfs.attributes +local md5_sum = md5.sum +local open = io.open +local os_date = os.date +local setcatcode = tex.setcatcode +local str_format = string.format +local sprint = tex.sprint +local write = tex.write +local utf8_char = unicode.utf8.char +local function escapehex(str) + write((gsub(str, ".", + function (ch) return format("%02X", byte(ch)) end))) +end +local charcat_table = l3kernel.charcat_table or 1 +local function charcat(charcode, catcode) + setcatcode(charcat_table, charcode, catcode) + sprint(charcat_table, utf8_char(charcode)) +end +l3kernel.charcat = charcat +local function filemdfivesum(name) + local file = kpse_find(name, "tex", true) + if file then + local f = open(file, "r") + if f then + local data = f:read("*a") + escapehex(md5_sum(data)) + f:close() + end + end +end +l3kernel.filemdfivesum = filemdfivesum +local function filemoddate(name) + local file = kpse_find(name, "tex", true) + if file then + local date = lfs_attr(file, "modification") + if date then + local d = os_date("*t", date) + if d.sec >= 60 then + d.sec = 59 + end + local u = os_date("!*t", date) + local off = 60 * (d.hour - u.hour) + d.min - u.min + if d.year ~= u.year then + if d.year > u.year then + off = off + 1440 + else + off = off - 1440 + end + elseif d.yday ~= u.yday then + if d.yday > u.yday then + off = off + 1440 + else + off = off - 1440 + end + end + local timezone + if off == 0 then + timezone = "Z" + else + local hours = floor(off / 60) + local mins = abs(off - hours * 60) + timezone = str_format("%+03d", hours) + .. "'" .. str_format("%02d", mins) .. "'" + end + write("D:" + .. str_format("%04d", d.year) + .. str_format("%02d", d.month) + .. str_format("%02d", d.day) + .. str_format("%02d", d.hour) + .. str_format("%02d", d.min) + .. str_format("%02d", d.sec) + .. timezone) + end + end +end +l3kernel.filemoddate = filemoddate +local function filesize(name) + local file = kpse_find(name, "tex", true) + if file then + local size = lfs_attr(file, "size") + if size then + write(size) + end + end +end +l3kernel.filesize = filesize +local function strcmp(A, B) if A == B then - tex_write("0") + write("0") elseif A < B then - tex_write("-1") + write("-1") else - tex_write("1") + write("1") end end l3kernel.strcmp = strcmp -local charcat_table = l3kernel.charcat_table or 1 -local function charcat (charcode, catcode) - tex_setcatcode(charcat_table, charcode, catcode) - tex_sprint(charcat_table, unicode_utf8_char(charcode)) -end -l3kernel.charcat = charcat |