From 412796f51a6c4e721018f37242013d62d7d82ad6 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Wed, 12 Nov 2014 12:15:04 +0100 Subject: 2014-11-12 11:58:00 --- scripts/context/lua/mtx-bibtex.lua | 52 +++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-bibtex.lua b/scripts/context/lua/mtx-bibtex.lua index c81fd596f..92036e3a5 100644 --- a/scripts/context/lua/mtx-bibtex.lua +++ b/scripts/context/lua/mtx-bibtex.lua @@ -19,6 +19,7 @@ local helpinfo = [[ convert bibtex database(s) to xml convert bibtex database(s) to lua + seatch bibtex database(s) @@ -29,6 +30,7 @@ local helpinfo = [[ mtxrun --script bibtex --tolua bibl-001.bib mtxrun --script bibtex --tolua --simple bibl-001.bib mtxrun --script bibtex --toxml bibl-001.bib bibl-002.bib bibl-003.bib biblio.xml + mtxrun --script bibtex --search --list --pattern=match(author:foo) bar.bib @@ -43,7 +45,9 @@ local application = logs.application { local report = application.report +require("util-seq") require("publ-dat") +require("publ-fnd") scripts = scripts or { } scripts.bibtex = scripts.bibtex or { } @@ -57,7 +61,7 @@ function scripts.bibtex.toxml(files) if filetype == "xml" then target = filename elseif filetype == "bib" then - bibtex.load(instance,filename) + bibtex.load { dataset = instance, filename = filename } else -- not supported end @@ -77,7 +81,8 @@ function scripts.bibtex.tolua(files) if filetype == "lua" then target = filename elseif filetype == "bib" then - bibtex.load(instance,filename) + bibtex.load { dataset = instance, filename = filename } + else -- not supported end @@ -92,7 +97,48 @@ function scripts.bibtex.tolua(files) end end -if environment.arguments.toxml then +function scripts.bibtex.search(files,pattern,list) + if pattern then + local dataset = publications.datasets["whatever"] + for i=1,#files do + local filename = resolvers.findfile(files[i]) + if filename and filename ~= "" then + publications.load { dataset = "whatever", filename = filename } + end + end + local found = publications.search(dataset,pattern) + local tags = table.sortedkeys(found) + if #tags == 0 then + report("no match") + elseif list then + report("%s matches:",#tags) + local result = { } + local luadata = dataset.luadata + for i=1,#tags do + local tag = tags[i] + local entry = luadata[tag] + result[i] = { + tag, + entry.year, + entry.author, + entry.title, + } + end + utilities.formatters.formatcolumns(result) + logs.newline() + for i=1,#result do + texio.write_nl(result[i]) + end + logs.newline() + else + report("%s matches: % t",#tags,tags) + end + end +end + +if environment.arguments.search then + scripts.bibtex.search(environment.files,environment.arguments.pattern,environment.arguments.list) +elseif environment.arguments.toxml then scripts.bibtex.toxml(environment.files) elseif environment.arguments.tolua then scripts.bibtex.tolua(environment.files) -- cgit v1.2.3