%D \module
%D   [      file=s-fnt-11,
%D        version=2006.02.01, % or so
%D          title=\CONTEXT\ Style File,
%D       subtitle=Listing Installed Fonts,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This code usd to be in the kernel but since it's hardly used
%D it's now a module.
%D
%D \starttyping
%D \showinstalledfonts[officinasans.*][all]
%D \showinstalledfonts[officinaserif.*][all]
%D \showinstalledfonts[officina.*itc.*][all]
%D
%D \showinstalledfonts[officina.*itc.*][all,new]
%D \stoptyping

\startluacode
function fonts.names.table(pattern,reload,all)
    local t = fonts.names.list(pattern,reload)
    if t then
        tex.sprint(tex.ctxcatcodes,"\\start\\nonknuthmode\\starttabulate[|T|T|T|T|T|]")
        tex.sprint(tex.ctxcatcodes,"\\NC hashname\\NC type\\NC fontname\\NC filename\\NC\\NR\\HL")
        for v,tv in table.sortedpairs(t) do
            local kind, name, file = tv[1], tv[2], tv[3]
            if all or v == string.lower(name) then
                if kind and name and file then
                    tex.sprint(tex.ctxcatcodes,string.format("\\NC %s\\NC %s\\NC %s\\NC %s\\NC\\NR",v,kind,name,file))
                else
                    logs.report("font table", "skipping %s", v)
                end
            end
        end
        tex.sprint(tex.ctxcatcodes,"\\stoptabulate\\stop")
    end
end
\stopluacode

\unprotect

\def\showinstalledfonts
  {\dodoubleempty\doshowinstalledfonts}

\def\doshowinstalledfonts[#1][#2]%
  {\bgroup
   \def\pattern{#1}%
   \def\all{false}%
   \def\reload{false}%
   \doifnothing\pattern{\def\pattern{.*}}%
   \processallactionsinset[#2][\v!new=>\def\reload{true},\v!all=>\def\all{true}]%
   \ctxlua{fonts.names.table("#1",\reload,\all)}%
   \egroup}

\protect \endinput
