summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2014-01-14 15:03:00 +0100
committerHans Hagen <pragma@wxs.nl>2014-01-14 15:03:00 +0100
commit9e6ed699c77bb2d08ab2c294fdb644046da2a6e8 (patch)
treedc994a7080f954e9c5fc1269c8529db754f42805 /scripts
parentc346c3825d2d63e307b0d9bb5c548b96c25c38d9 (diff)
downloadcontext-9e6ed699c77bb2d08ab2c294fdb644046da2a6e8.tar.gz
beta 2014.01.14 15:03
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-bibtex.lua106
1 files changed, 106 insertions, 0 deletions
diff --git a/scripts/context/lua/mtx-bibtex.lua b/scripts/context/lua/mtx-bibtex.lua
new file mode 100644
index 000000000..c81fd596f
--- /dev/null
+++ b/scripts/context/lua/mtx-bibtex.lua
@@ -0,0 +1,106 @@
+if not modules then modules = { } end modules ['mtx-bibtex'] = {
+ version = 1.002,
+ comment = "this script is part of publication support",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE",
+ license = "see context related readme files"
+}
+
+local helpinfo = [[
+<?xml version="1.0"?>
+<application>
+ <metadata>
+ <entry name="name">mtx-bibtex</entry>
+ <entry name="detail">bibtex helpers</entry>
+ <entry name="version">1.00</entry>
+ </metadata>
+ <flags>
+ <category name="basic">
+ <subcategory>
+ <flag name="toxml"><short>convert bibtex database(s) to xml</short></flag>
+ <flag name="tolua"><short>convert bibtex database(s) to lua</short></flag>
+ </subcategory>
+ </category>
+ </flags>
+ <examples>
+ <category>
+ <title>Example</title>
+ <subcategory>
+ <example><command>mtxrun --script bibtex --tolua bibl-001.bib</command></example>
+ <example><command>mtxrun --script bibtex --tolua --simple bibl-001.bib</command></example>
+ <example><command>mtxrun --script bibtex --toxml bibl-001.bib bibl-002.bib bibl-003.bib biblio.xml</command></example>
+ </subcategory>
+ </category>
+ </examples>
+</application>
+]]
+
+local application = logs.application {
+ name = "mtx-bibtex",
+ banner = "bibtex helpers",
+ helpinfo = helpinfo,
+}
+
+local report = application.report
+
+require("publ-dat")
+
+scripts = scripts or { }
+scripts.bibtex = scripts.bibtex or { }
+
+function scripts.bibtex.toxml(files)
+ local instance = bibtex.new()
+ local target = "mtx-bibtex-output.xml"
+ for i=1,#files do
+ local filename = files[i]
+ local filetype = file.suffix(filename)
+ if filetype == "xml" then
+ target = filename
+ elseif filetype == "bib" then
+ bibtex.load(instance,filename)
+ else
+ -- not supported
+ end
+ end
+ bibtex.converttoxml(instance,true)
+ instance.shortcuts = nil
+ instance.luadata = nil
+ xml.save(instance.xmldata,target)
+end
+
+function scripts.bibtex.tolua(files)
+ local instance = bibtex.new()
+ local target = "mtx-bibtex-output.lua"
+ for i=1,#files do
+ local filename = files[i]
+ local filetype = file.suffix(filename)
+ if filetype == "lua" then
+ target = filename
+ elseif filetype == "bib" then
+ bibtex.load(instance,filename)
+ else
+ -- not supported
+ end
+ end
+ instance.shortcuts = nil
+ instance.xmldata = nil
+ bibtex.analyze(instance)
+ if environment.arguments.simple then
+ table.save(target,instance)
+ else
+ table.save(target,instance.luadata)
+ end
+end
+
+if environment.arguments.toxml then
+ scripts.bibtex.toxml(environment.files)
+elseif environment.arguments.tolua then
+ scripts.bibtex.tolua(environment.files)
+elseif environment.arguments.exporthelp then
+ application.export(environment.arguments.exporthelp,environment.files[1])
+else
+ application.help()
+end
+
+-- scripts.bibtex.toxml { "tugboat.bib" }
+-- scripts.bibtex.tolua { "tugboat.bib" }