Skip to content

Instantly share code, notes, and snippets.

@phi-gamma
Last active January 25, 2016 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phi-gamma/404e587650d43af14f2d to your computer and use it in GitHub Desktop.
Save phi-gamma/404e587650d43af14f2d to your computer and use it in GitHub Desktop.
making sense of a windows registy dump
#!/usr/bin/env texlua
kpse.set_program_name "luatex"
require "lualibs"
local rawset = rawset
local lpeg = require "lpeg"
local P, R, S = lpeg.P, lpeg.R, lpeg.S
local lpegmatch = lpeg.match
local C, Cc, Cf = lpeg.C, lpeg.Cc, lpeg.Cf
local Cg, Cmt, Cs, Ct = lpeg.Cg, lpeg.Cmt, lpeg.Cs, lpeg.Ct
local linebreak = S"\n\r"
local eol = P"\n\r" + P"\r\n" + linebreak
local spacing = S" \t\v"
local whitespace = spacing + linebreak
local digit = R"09"
local comma = P","
local test_parser = true
local lparen = P"("
local rparen = P")"
local fname = (1 - (spacing^0 * eol))^1
local reg_sz = P"REG_SZ"
local parnum = lparen * C(digit^1) * rparen --- ???
local container = P"(TrueType)" / "ttf"
local size = C(digit^1) / tonumber
local sizes = Ct (size * (comma * size)^0)
--- Some names seem to contain a semi-regular component holding
--- a number enclosed in parentheses after the file name. Perhaps these
--- specify a measure of some sorts like the dpi size, but one can
--- merely speculate.
local options = --[[ parnum + ]] container + sizes
local name = (1 - (spacing^1 * (reg_sz + options)))^1
local entry = Cg ( spacing^1 * C (name)
--* spacing^1 * C ((1 - eol)^1) * eol)
* Ct ( spacing^1
* (Cg (Ct (options), "options") * spacing^1)^-1
* reg_sz
* spacing^1 * Cg (C (fname), "filename")
* spacing^0 * eol))
local junk = (1 - eol)^0 * eol
local line = entry + junk
local fontnames = Cf (Ct"" * line^1, rawset)
if not test_parser then return end
do --- functionality test
local data = [==[
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
Arial (TrueType) REG_SZ arial.ttf
Comic Sans MS (TrueType) REG_SZ comic.ttf
Verdana Bold Italic (TrueType) REG_SZ verdanaz.ttf
Courier 10,12,15 REG_SZ COURE.FON
MS Serif 8,10,12,14,18,24 REG_SZ SERIFE.FON
MS Sans Serif 8,10,12,14,18,24 REG_SZ SSERIFE.FON
Small Fonts REG_SZ SMALLE.FON
Small Fonts (120) REG_SZ SMALLF.FON
Inconsolata LGC Bold Italic (TrueType) REG_SZ InconsolataLGC-Bold-Italic_0.otf
]==]
inspect (lpegmatch (fontnames, data))
inspect (table.fromhash (lpegmatch (fontnames, data)))
print (#table.fromhash (lpegmatch (fontnames, data)))
end --[[ [parser test] ]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment