diff options
author | Karl Berry <karl@freefriends.org> | 2015-05-11 21:37:36 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-05-11 21:37:36 +0000 |
commit | 0053a5222ec78ba41126c246eafd8cdb02f9a56a (patch) | |
tree | 22b38b1430bb1084ec8357362fc51d55ffd2fddb /Master/texmf-dist/tex/context/base/publ-ini.lua | |
parent | c4e86cc3b89e06b5f6a6ea80c907cfa69a7231da (diff) |
context/11may15
git-svn-id: svn://tug.org/texlive/trunk@37341 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/publ-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/publ-ini.lua | 275 |
1 files changed, 211 insertions, 64 deletions
diff --git a/Master/texmf-dist/tex/context/base/publ-ini.lua b/Master/texmf-dist/tex/context/base/publ-ini.lua index 30d0c890882..04a3f1cc116 100644 --- a/Master/texmf-dist/tex/context/base/publ-ini.lua +++ b/Master/texmf-dist/tex/context/base/publ-ini.lua @@ -115,6 +115,7 @@ local ctx_gobbletwoarguments = context.gobbletwoarguments local ctx_btxdirectlink = context.btxdirectlink local ctx_btxhandlelistentry = context.btxhandlelistentry local ctx_btxhandlelisttextentry = context.btxhandlelisttextentry +local ctx_btxhandlecombientry = context.btxhandlecombientry local ctx_btxchecklistentry = context.btxchecklistentry local ctx_btxchecklistcombi = context.btxchecklistcombi @@ -154,6 +155,8 @@ local ctx_btxstartsubcite = context.btxstartsubcite local ctx_btxstopsubcite = context.btxstopsubcite local ctx_btxstartlistentry = context.btxstartlistentry local ctx_btxstoplistentry = context.btxstoplistentry +local ctx_btxstartcombientry = context.btxstartcombientry +local ctx_btxstopcombientry = context.btxstopcombientry local ctx_btxlistsetup = context.btxlistsetup local ctx_btxflushauthor = context.btxflushauthor local ctx_btxsetnoflistentries = context.btxsetnoflistentries @@ -340,10 +343,10 @@ do local initialize = nil initialize = function(t) - usedentries = allocate { } - citetolist = allocate { } - listtocite = allocate { } - listtolist = allocate { } + usedentries = allocate { } + citetolist = allocate { } + listtocite = allocate { } + listtolist = allocate { } local names = { } local internals = structures.references.internals local p_collect = (C(R("09")^1) * Carg(1) / function(s,entry) listtocite[tonumber(s)] = entry end + P(1))^0 @@ -477,15 +480,16 @@ local findallused do local finder = publications.finder findallused = function(dataset,reference,internal) - local current = datasets[dataset] - local finder = publications.finder -- for the moment, not yet in all betas - local find = finder and finder(current,reference) - local tags = not find and settings_to_array(reference) - local todo = { } - local okay = { } -- only if mark - local set = usedentries[dataset] - local valid = current.luadata - local ordered = current.ordered + local current = datasets[dataset] + local finder = publications.finder -- for the moment, not yet in all betas + local find = finder and finder(current,reference) + local tags = not find and settings_to_array(reference) + local todo = { } + local okay = { } -- only if mark + local set = usedentries[dataset] + local valid = current.luadata + local ordered = current.ordered + local combined = current.combined if set then local registered = { } local function register(tag) @@ -495,6 +499,16 @@ local findallused do registered[tag] = true end local entry = set[tag] + if not entry then + local parent = combined[tag] + if parent then + entry = set[parent] + end + if entry then + report("using reference of parent %a for %a",parent,tag) + tag = parent + end + end if entry then -- only once in a list but at some point we can have more (if we -- decide to duplicate) @@ -533,22 +547,22 @@ local findallused do okay[#okay+1] = entry end todo[tag] = true + return tag end if reference == "*" then tags = { } for i=1,#ordered do local tag = ordered[i].tag - register(tag) + tag = register(tag) tags[#tags+1] = tag end elseif find then --- print("case 1.1") tags = { } for i=1,#ordered do local entry = ordered[i] if find(entry) then local tag = entry.tag - register(tag) + tag = register(tag) tags[#tags+1] = tag end end @@ -557,11 +571,11 @@ local findallused do reported[reference] = true end else --- print("case 1.2") for i=1,#tags do - local tag = tags[i] + local tag = tags[i] if valid[tag] then - register(tag) + tag = register(tag) + tags[i] = tag elseif not reported[tag] then reported[tag] = true report_cite("non-existent entry %a in %a",tag,dataset) @@ -570,12 +584,15 @@ local findallused do end else if find then --- print("case 2.1") tags = { } for i=1,#ordered do local entry = ordered[i] if find(entry) then - local tag = entry.tag + local tag = entry.tag + local parent = combined[tag] + if parent then + tag = parent + end tags[#tags+1] = tag todo[tag] = true end @@ -585,9 +602,13 @@ local findallused do reported[reference] = true end else --- print("case 2.2") for i=1,#tags do - local tag = tags[i] + local tag = tags[i] + local parent = combined[tag] + if parent then + tag = parent + tags[i] = tag + end if valid[tag] then todo[tag] = true elseif not reported[tag] then @@ -1060,9 +1081,11 @@ do local userdata = listentry.userdata local btxspc = userdata and userdata.btxspc if btxspc then - -- this will become a specification entry + -- we could act on the 3rd arg returned by getcasted but in general any string will do + -- so we deal with it in the author hashers ... maybe some day ... local author = getcasted(dataset,tag,field,specifications[btxspc]) - if type(author) == "table" then + local kind = type(author) + if kind == "table" or kind == "string" then if u then u = listentry.entries.text -- hm else @@ -1633,17 +1656,20 @@ do end end + + -- tag | listindex | reference | userdata | dataindex + local methods = { } lists.methods = methods methods[v_dataset] = function(dataset,rendering,keyword) - -- why only once unless criterium=all? local current = datasets[dataset] local luadata = current.luadata local list = rendering.list for tag, data in sortedhash(luadata) do if not keyword or validkeyword(dataset,tag,keyword) then - list[#list+1] = { tag, false, 0, false, false, data.index or 0} + local index = data.index or 0 + list[#list+1] = { tag, index, 0, false, index } end end end @@ -1666,7 +1692,7 @@ do local tag = u.btxref if tag and (not keyword or validkeyword(dataset,tag,keyword)) then local data = luadata[tag] - list[#list+1] = { tag, listindex, 0, u, u.btxint, data and data.index or 0 } + list[#list+1] = { tag, listindex, 0, u, data and data.index or 0 } end end end @@ -1700,6 +1726,7 @@ do if u then -- better check on metadata.kind == "btx" local set = u.btxset or v_default if set == dataset then +-- inspect(structures.references.internals[tonumber(u.btxint)]) local tag = u.btxref if not tag then -- problem @@ -1714,7 +1741,7 @@ do l[#l+1] = u.btxint else local data = luadata[tag] - local l = { tag, listindex, 0, u, u.btxint, data and data.index or 0 } + local l = { tag, listindex, 0, u, data and data.index or 0 } list[#list+1] = l traced[tag] = l end @@ -1722,7 +1749,7 @@ do done[tag] = section alldone[tag] = true local data = luadata[tag] - list[#list+1] = { tag, listindex, 0, u, u.btxint, data and data.index or 0 } + list[#list+1] = { tag, listindex, 0, u, data and data.index or 0 } end end if tag then @@ -1798,6 +1825,7 @@ do local current = datasets[dataset] local luadata = current.luadata local details = current.details + local combined = current.combined local newlist = { } local lastreferencenumber = groups[group] -- current.lastreferencenumber or 0 for i=1,#list do @@ -1819,31 +1847,55 @@ do else list = newlist end +-- local combined = { } + local newlist = { } +-- for i=1,#list do +-- local userdata = list[i][4] +-- if userdata then +-- local com = userdata.btxcom +-- if com then +-- com = settings_to_array(com) +-- for i=1,#com do +-- local c = com[i] +-- if not combined[c] then +-- report("ignoring list entry for tag %a due to combined usage in %a ",c,tag) +-- combined[c] = true +-- end +-- end +-- end +-- end +-- end + local tagtolistindex = { } + rendering.tagtolistindex = tagtolistindex for i=1,#list do local li = list[i] local tag = li[1] - local entry = luadata[tag] - if entry then - local detail = details[tag] - if detail then - local referencenumber = detail.referencenumber - if not referencenumber then - lastreferencenumber = lastreferencenumber + 1 - referencenumber = lastreferencenumber - detail.referencenumber = lastreferencenumber + if not combined[tag] then + local entry = luadata[tag] + if entry then + local detail = details[tag] + if detail then + local referencenumber = detail.referencenumber + if not referencenumber then + lastreferencenumber = lastreferencenumber + 1 + referencenumber = lastreferencenumber + detail.referencenumber = lastreferencenumber + end + li[3] = referencenumber + else + report("missing details for tag %a in dataset %a (enhanced: %s)",tag,dataset,current.enhanced and "yes" or "no") + -- weird, this shouldn't happen .. all have a detail + lastreferencenumber = lastreferencenumber + 1 + details[tag] = { referencenumber = lastreferencenumber } + li[3] = lastreferencenumber end - li[3] = referencenumber - else - report("missing details for tag %a in dataset %a (enhanced: %s)",tag,dataset,current.enhanced and "yes" or "no") - -- weird, this shouldn't happen .. all have a detail - lastreferencenumber = lastreferencenumber + 1 - details[tag] = { referencenumber = lastreferencenumber } - li[3] = lastreferencenumber + tagtolistindex[tag] = i end + newlist[#newlist+1] = li end end groups[group] = lastreferencenumber - rendering.list = list + rendering.list = newlist end function lists.fetchentries(dataset) @@ -1997,14 +2049,56 @@ do end end + function lists.combiinlist(dataset,tag) + local rendering = renderings[dataset] + local list = rendering.list + local toindex = rendering.tagtolistindex + return toindex and toindex[tag] + end + + function lists.flushcombi(dataset,tag) + local rendering = renderings[dataset] + local list = rendering.list + local toindex = rendering.tagtolistindex + local listindex = toindex and toindex[tag] + if listindex then + local li = list[listindex] + if li then + local data = datasets[dataset] + local luadata = data.luadata + local details = data.details + local tag = li[1] + local listindex = li[2] + local n = li[3] + local entry = luadata[tag] + local detail = details[tag] + ctx_btxstartcombientry() + ctx_btxsetcurrentlistindex(listindex) + ctx_btxsetcategory(entry.category or "unknown") + ctx_btxsettag(tag) + ctx_btxsetnumber(n) + local language = entry.language + if language then + ctx_btxsetlanguage(language) + end + local authorsuffix = detail.authorsuffix + if authorsuffix then + ctx_btxsetsuffix(authorsuffix) + end + ctx_btxhandlecombientry() + ctx_btxstopcombientry() + end + end + end + function lists.flushentry(dataset,i,textmode) local rendering = renderings[dataset] local list = rendering.list - local data = datasets[dataset] - local luadata = data.luadata - local details = data.details local li = list[i] if li then + local data = datasets[dataset] + local luadata = data.luadata + local details = data.details local tag = li[1] local listindex = li[2] local n = li[3] @@ -2025,17 +2119,6 @@ do if language then ctx_btxsetlanguage(language) end - local bl = li[5] - if bl and bl ~= "" then - ctx_btxsetbacklink(bl) - -- ctx_btxsetbacktrace(concat(li," ",5)) -- two numbers - else - -- nothing - end - local authorsuffix = detail.authorsuffix - if authorsuffix then - ctx_btxsetsuffix(authorsuffix) - end local userdata = li[4] if userdata then local b = userdata.btxbtx @@ -2046,6 +2129,14 @@ do if a then ctx_btxsetafter(a) end + local bl = userdata.btxint + if bl and bl ~= "" then + ctx_btxsetbacklink(bl) + end + end + local authorsuffix = detail.authorsuffix + if authorsuffix then + ctx_btxsetsuffix(authorsuffix) end rendering.userdata = userdata if textmode then @@ -2142,11 +2233,23 @@ do } implement { + name = "btxflushlistcombi", + actions = lists.flushcombi, + arguments = { "string", "string" } + } + + implement { name = "btxdoifelsesameasprevious", actions = { lists.sameasprevious, ctx_doifelse }, arguments = { "string", "integer", "string", "integer", "string" } } + implement { + name = "btxdoifelsecombiinlist", + actions = { lists.combiinlist, ctx_doifelse }, + arguments = { "string", "string" } + } + end do @@ -2391,7 +2494,7 @@ do tobemarked = specification.markentry and todo -- if not found or #found == 0 then - report("nothing found for %a",reference) + report("no entry %a found in dataset %a",reference,dataset) elseif not setup then report("invalid reference for %a",reference) else @@ -2402,6 +2505,7 @@ do local luadata = datasets[dataset].luadata for i=1,#found do local entry = found[i] +-- inspect(entry) local tag = entry.userdata.btxref local ldata = luadata[tag] local data = { @@ -2409,6 +2513,7 @@ do language = ldata.language, dataset = dataset, tag = tag, + combis = entry.userdata.btxcom, -- luadata = ldata, } setter(data,dataset,tag,entry) @@ -2455,6 +2560,10 @@ do if language then ctx_btxsetlanguage(language) end +local combis = entry.combis +if combis then + ctx_btxsetcombis(combis) +end if not getter(entry,last,nil,specification) then ctx_btxsetfirst("") -- (f_missing(tag)) end @@ -2816,8 +2925,10 @@ do else return false end - else + elseif ak and bk then return ak < bk + else + return false end end @@ -3109,7 +3220,14 @@ do end listvariants[v_yes] = listvariants.num - listvariants.bib = listvariants.num + + function listvariants.tag(dataset,block,tag,variant,listindex) + ctx_btxsetfirst(tag) + if trace_detail then + report("expanding %a list setup %a","tag",variant) + end + ctx_btxnumberingsetup(variant or "tag") + end function listvariants.short(dataset,block,tag,variant,listindex) local short = getdetail(dataset,tag,"shorthash") @@ -3154,3 +3272,32 @@ do end end + +-- a helper + +do + + -- local context = context + -- local lpegmatch = lpeg.match + local splitter = lpeg.tsplitat(":") + + interfaces.implement { + name = "checkinterfacechain", + arguments = { "string", "string" }, + actions = function(str,command) + local chain = lpegmatch(splitter,str) + if #chain > 0 then + local command = context[command] + local parent = "" + local child = chain[1] + command(child,parent) + for i=2,#chain do + parent = child + child = child .. ":" .. chain[i] + command(child,parent) + end + end + end + } + +end |