summaryrefslogtreecommitdiff
path: root/scripts/mkcharacters
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-02-11 06:27:04 +0100
committerPhilipp Gesang <phg42.2a@gmail.com>2014-02-11 06:27:04 +0100
commitd9825168b0fb7b07e315879584487f9d4d9e9494 (patch)
tree5350b3b748209ff2754c70ed4bc01bee586ac178 /scripts/mkcharacters
parentf874408006c90ba4ecdf96fb84a2a560fb30429f (diff)
downloadluaotfload-d9825168b0fb7b07e315879584487f9d4d9e9494.tar.gz
[*] move mkcharacters, mktests, mkglyphlist, mkstatus to separate subdirectory scripts
Diffstat (limited to 'scripts/mkcharacters')
-rwxr-xr-xscripts/mkcharacters156
1 files changed, 156 insertions, 0 deletions
diff --git a/scripts/mkcharacters b/scripts/mkcharacters
new file mode 100755
index 0000000..5d4a2f4
--- /dev/null
+++ b/scripts/mkcharacters
@@ -0,0 +1,156 @@
+#!/usr/bin/env texlua
+-----------------------------------------------------------------------
+-- FILE: mkcharacters.lua
+-- USAGE: ./mkcharacters.lua
+-- DESCRIPTION: import parts of char-def.lua
+-- REQUIREMENTS: lua, ConTeXt, the lualibs package
+-- AUTHOR: Philipp Gesang (Phg), <phg42.2a@gmail.com>
+-- VERSION: 2.4
+-- CREATED: 2013-05-17 12:41:39+0200
+-----------------------------------------------------------------------
+-- we create a stripped-down version of char-def.lua
+-----------------------------------------------------------------------
+
+-----------------------------------------------------------------------
+-- config
+-----------------------------------------------------------------------
+local charfile = "./luaotfload-characters.lua"
+local chardef = "/home/phg/base/char-def.lua"
+
+--- for every code point char-def.lua provides a set of fields. they
+--- are:
+---
+--- * adobename
+--- * category
+--- * cjkwd
+--- * comment
+--- * contextname
+--- * description
+--- * direction
+--- * lccode
+--- * linebreak
+--- * mathclass
+--- * mathextensible
+--- * mathfiller
+--- * mathname
+--- * mathspec
+--- * mathstretch
+--- * mathsymbol
+--- * mirror
+--- * shcode
+--- * specials
+--- * textclass
+--- * uccode
+--- * unicodeslot
+--- * variants
+
+local import = {
+ "direction", "mirror", --> πολυγλωσσία/uax9
+ "category", --> https://gist.github.com/phi-gamma/5812290
+ "textclass", --> https://gist.github.com/phi-gamma/6488187
+}
+
+-----------------------------------------------------------------------
+-- includes
+-----------------------------------------------------------------------
+
+kpse.set_program_name"luatex"
+
+for _, lib in next, { "lualibs-lua.lua",
+ "lualibs-lpeg.lua",
+ "lualibs-table.lua", } do
+ local found = assert(kpse.find_file(lib, "lua"),
+ "Could not locate " .. lib .. ".\n"
+ .. "Please install the lualibs package.")
+ require(found)
+end
+
+if not (chardef and lfs.isfile(chardef)) then
+ --- we could grab the file from contextgarden but as Context is part
+ --- of TL it’s not worth bothering
+ chardef = assert(kpse.find_file("char-def.lua", "lua"),
+ "Could not find ConTeXt.")
+end
+
+-----------------------------------------------------------------------
+-- functionality
+-----------------------------------------------------------------------
+
+local get_characters = function ( )
+ local data
+ local inchan = io.open(chardef, "r")
+ if not inchan then
+ io.write("Could not open file for reading: "..chardef.."\n.")
+ goto fail
+ end
+ data = inchan:read "*all"
+ inchan:close()
+ data = loadstring(data)
+ if data then
+ data() --> characters.data
+ data = nil
+ collectgarbage "collect"
+ if characters.data and next(characters.data) then
+ return characters.data
+ end
+ io.write "Character table empty.\n"
+ goto fail
+ end
+ io.write(chardef .. " is not a valid Lua file.\n")
+ ::fail::
+ io.write "Emergency exit.\n"
+ os.exit(1)
+end
+
+local extract_fields_indeed
+extract_fields_indeed = function (data, acc, lastidx)
+ local idx, char = next(data, lastidx)
+ if idx then
+ local imported = { }
+ for i=1, #import do
+ local field = import[i]
+ imported[field] = char[field]
+ end
+ acc[idx] = imported
+ return extract_fields_indeed(data, acc, idx)
+ end
+ return acc
+end
+
+local extract_fields = function (data)
+ return extract_fields_indeed(data, {}, nil)
+end
+
+local writedata = function (data)
+ local outchan = io.open(charfile, "w")
+ if not outchan then
+ io.write("Could not open "..charfile.." for writing.\n")
+ return false
+ end
+ outchan:write(data)
+ outchan:close()
+ return true
+end
+
+do
+ local chardata = get_characters()
+ local stripped = extract_fields(chardata)
+ local serialized = table.serialize(stripped, true, {
+ compact = true,
+ noquotes = true,
+ hexify = true, --- for consistency with char-def
+ })
+ if writedata(serialized) then
+ goto done
+ end
+ goto fail
+end
+
+::done::
+ os.exit(0)
+
+::fail::
+ io.write "Emergency exit.\n"
+ os.exit(1)
+
+--- vim:ft=lua:ts=2:et:sw=2