Modulo:mfarado

El Vikivortaro
 MODULO
Memtesto ne disponeblas.

--[===[

MODULE "MFARADO" (kategorio vortfarado vortgrupigado)

"eo.wiktionary.org/wiki/Modulo:mfarado" <!--2023-Nov-21-->

Purpose: brews visible content (box) and 2 or more cat insertions
         from pagename

Utilo: kreas videblan enhavon (skatolon) kaj 2 aux pli kategorienmetojn
       el pagxonomo

Manfaat: membutat isi terlihat (kotak) dan 2 atau lebih masukan kategori
         dari nama halaman

Syfte: skapar synligt innehaall (ruta) och 2 eller fler kategoriinlaeggningar
       fraan sidnamn

Used by templates / Uzata far sxablonoj / Digunakan oleh templat:
* kat-farado (EO)

Required submodules / Bezonataj submoduloj / Submodul yang diperlukan:
* "loaddata-tbllingvoj" T76 in turn requiring template "tbllingvoj" (EO)
* "loaddata-tblbahasa" T76 in turn requiring template "tblbahasa" (ID)
* "mrooteo" in turn requiring template "radikoj" (only if activated)

Required images:
* "File:Hidden icon.png"

Required templates:
* YES, see above

This module can accept parameters whether sent to itself (own frame) or
to the caller (caller's frame). If there is a parameter "caller=true"
on the own frame then that own frame is discarded in favor of the
caller's one.

Incoming: * 1 ordinary anonymous and optional parameter
            * only permitted value is "K" (uppercase letter) to indicate
              "compound quasi-root", otherwise it must be omitted altogether,
              crucial for -eo-, permitted for other languages, gives an extra
              category "Kunmetita kvazauxelemento" only for -eo- (without lang
              name, consistently with other categories as named by "mrooteo")
          * 3 hidden named and optional parameters
            * "pagenameoverridetestonly=" can directly cause #E01
            * "nsnumberoverridetestonly=" can indirectly cause #E04
            * "detrc=" no error possible

Returned: * one string with visible part (HTML box) and category part

Most of the relevant information is peeked from the pagename and thus
ordinary parameters are barely needed.

To be called from category namespace only.

Errors:
* we generate errors #E01 ... #E12
* we import errors from submodule "rooteo", those
  have 20 added thus begin from #E21

]===]

local exporttable = {}

------------------------------------------------------------------------

---- CONSTANTS [O] ----

------------------------------------------------------------------------

  -- uncommentable EO vs ID constant strings (core site-related features)

  local constrpriv = "eo"                            -- EO (privileged site language)
  -- local constrpriv = "id"                            -- ID (privileged site language)
  local constringvoj = "Modulo:loaddata-tbllingvoj"  -- EO
  -- local constringvoj = "Modul:loaddata-tblbahasa"    -- ID
  local constrrteo = "Modulo:mrooteo"     -- EO
  -- local constrrteo = "Modul:mrooteo"      -- ID
  local constrapxq = "Aldono"             -- EO (used only via "lfikataldigu")
  -- local constrapxq = "Lampiran"           -- ID (used only via "lfikataldigu")
  local constrkatq = "Kategorio"          -- EO (used only via "lfikataldigu")
  -- local constrkatq = "Kategori"           -- ID (used only via "lfikataldigu")

  -- constant table -- ban list -- add obviously invalid access codes (2-letter or 3-letter) only

  -- length of the list is NOT stored anywhere, the processing stops
  -- when type "nil" is encountered, used by "lfivalidatelnkoadv" only

  -- controversial codes (sh sr hr), (zh cmn)
  -- "en.wiktionary.org/wiki/Wiktionary:Language_treatment" excluded languages
  -- "en.wikipedia.org/wiki/Spurious_languages"
  -- "iso639-3.sil.org/code/art" only valid in ISO 639-2
  -- "iso639-3.sil.org/code/gem" only valid in ISO 639-2 and 639-5, "collective"
  -- "iso639-3.sil.org/code/zxx" "No linguistic content"

  local contabisbanned = {}
  contabisbanned = {'by','dc','ll','jp','art','deu','eng','epo','fra','gem','ger','ido','lat','por','rus','spa','swe','tup','zxx'} -- 1...19

  -- surrogate transcoding table (only needed for EO)

  local contabtransluteo = {}
  contabtransluteo[ 67] = 0xC488 -- CX
  contabtransluteo[ 99] = 0xC489 -- cx
  contabtransluteo[ 71] = 0xC49C -- GX
  contabtransluteo[103] = 0xC49D -- gx
  contabtransluteo[ 74] = 0xC4B4 -- JX
  contabtransluteo[106] = 0xC4B5 -- jx
  contabtransluteo[ 83] = 0xC59C -- SX
  contabtransluteo[115] = 0xC59D -- sx
  contabtransluteo[ 85] = 0xC5AC -- UX breve
  contabtransluteo[117] = 0xC5AD -- ux breve

  -- constant strings (error circumfixes)

  local constrelabg = '<span class="error"><b>'  -- lagom whining begin
  local constrelaen = '</b></span>'              -- lagom whining end
  local constrlaxhu = '&nbsp;&#42;&#42;&nbsp;'   -- lagom -> huge circumfix " ** "

  -- uncommentable EO vs ID string (caller name for error messages)

  local constrkoll = 'sxablono "kat-farado"'  -- EO augmented name of the caller (semi-hardcoded, we do NOT peek it) !!!FIXME!!!
  -- local constrkoll = 'templat "kat-farado"'   -- ID augmented name of the caller (semi-hardcoded, we do NOT peek it)

  -- uncommentable EO vs ID constant table (error messages)

  -- #E02...#E99, note that #E00 and #E01 are NOT supposed to be included here

  local contaberaroj = {}
  contaberaroj[2] = 'Maksimume unu parametro estas transprenata far \\@, legu gxian dokumentajxon'   -- EO #E02 change to unknown param and move
  -- contaberaroj[2] = 'Tidak lebih dari satu parameter bisa dimakan oleh \\@, bacalah dokumentasinya'  -- ID #E02 !!!FIXME!!!
  contaberaroj[3] = 'La sola permesita valoro de anonima parametro por \\@ estas "K"'                -- EO #E03 reserved value
  -- contaberaroj[3] = 'Isi satu-satunya parameter anonim yang benar untuk \\@ adalah "K"'              -- ID #E03 !!!FIXME!!!
  contaberaroj[4] = 'Erara nomspaco (estu 14, "Kategorio:") por \\@'                                 -- EO #E04
  -- contaberaroj[4] = 'Ruang nama salah (sebaiknya 14, "Kategori:") untuk \\@'                         -- ID #E04
  contaberaroj[ 5] = 'Evidente nevalida lingvokodo en \\@'                                -- EO #E05
  -- contaberaroj[ 5] = 'Kode bahasa jelas-jelas salah dalam \\@'                            -- ID #E05
  contaberaroj[10] = 'Erara pagxonomo (neniu el 3) por \\@'                               -- EO #E10
  -- contaberaroj[10] = 'Nama halaman salah (tidak satu dari 3) untuk \\@'                   -- ID #E10
  contaberaroj[11] = 'Erara pagxonomo por \\@'                                            -- EO #E11
  -- contaberaroj[11] = 'Nama halaman salah untuk \\@'                                       -- ID #E11
  contaberaroj[12] = 'Submodulo "mrooteo" ne redonis tabelon'                             -- EO #E12
  -- contaberaroj[12] = 'Submodul "mrooteo" gagal memberi kembali tabel'                     -- EO #E12

  -- uncommentable EO vs ID constant tables (boasting)

  -- "numowntyp" -- 0 invalid | 1 vorto 2 frazo 3 vortgrupo

  local contabboasting = {}
  contabboasting[1] = "En cxi tiu kasxita kategorio trovigxas vortoj enhavantaj la morfemon" -- follows morpheme type by letter and name
  contabboasting[2] = "En cxi tiu kasxita kategorio trovigxas frazoj enhavantaj la vorton"
  contabboasting[3] = "En cxi tiu kasxita kategorio trovigxas vortgrupoj enhavantaj la vorton"
  contabboasting[10] = "Kunmetita kvazauxelemento"

  -- uncommentable EO vs ID constant tables (dual use: mortyp:s and scripts via "lfhseizetext")

  -- "nummortyp" -- 0 invalid | 67 C 73 I 77 M 78 N 80 P 85 U

  local contabmosc = {}
  contabmosc["C"]   = "cirkumfikson"    -- EO
  contabmosc["I"]   = "infikson"        -- EO
  contabmosc["M"]   = "memstaran"       -- EO
  contabmosc["N"]   = "nememstaran"     -- EO
  contabmosc["P"]   = "prefikson"       -- EO
  contabmosc["U"]   = "sufikson"        -- EO
  contabmosc["zhT"] = "tradicia"        -- EO
  contabmosc["zhS"] = "simpligita"      -- EO
  contabmosc["zhK"] = "komuna"          -- EO
  contabmosc["zhP"] = "pinjina"         -- EO
  contabmosc["jaK"] = "kangxia"         -- EO
  contabmosc["jaH"] = "hiragana"        -- EO
  contabmosc["jaR"] = "romanigita"      -- EO
  contabmosc["hrC"] = "cirila"          -- EO
  contabmosc["hrL"] = "latina"          -- EO

  -- constant table (HTML)

  local contabhtml = {}
  contabhtml[0] = '<table style="border:1px solid #A0A0A0; background:#F0F0F0; width:95%; margin:0.6em auto 0.6em auto; padding:0.6em; text-align:justify;">'
  contabhtml[1] = '<tr><td style="width:30px;">[[File:Hidden icon.png|50px]]</td><td style="padding-left:1em;">'
  contabhtml[2] = '</td></tr></table>'

  -- constants to control behaviour from source AKA semi-hardcoded parameters

  local conboouseeox  = true   -- "true" to enable eo-specific submodule
  local conbookodlng  = false  -- "true" to allow long codes like "zh-min-nan"
  local conboomiddig  = false  -- "true" to allow middle digit "s7a"

------------------------------------------------------------------------

---- SPECIAL STUFF OUTSIDE MAIN [B] ----

------------------------------------------------------------------------

  -- SPECIAL VAR:S

local qldingvoj = {}     -- type "table" and nested
local qeorooteo = {}     -- type "table" with type "function" inside
local qboodetrc = true   -- from "detrc=true" but default is "true" !!!
local qstrtrace = '<br>' -- for main & sub:s, debug report request by "detrc="
local qbooguard = false  -- only for the guard test, pass to other var ASAP

  -- GUARD AGAINST INTERNAL ERROR & TWO IMPORTS

qbooguard = ((type(constrpriv)~='string') or (type(constringvoj)~='string') or (type(constrrteo)~='string') or (type(constrapxq)~='string') or (type(constrkatq)~='string') or (type(constrkoll)~='string'))
if (not qbooguard) then
  qldingvoj = mw.loadData(constringvoj) -- can crash here
  qbooguard = (type(qldingvoj)~='table') -- seems to be always false
end--if
if ((not qbooguard) and conboouseeox) then
  qeorooteo = require(constrrteo) -- can crash here despite guarding ??
  qbooguard = (type(qeorooteo)~='table')
end--if

------------------------------------------------------------------------

---- DEBUG FUNCTIONS [D] ----

------------------------------------------------------------------------

-- Local function LFTRACEMSG

-- Enhance upvalue "qstrtrace" with fixed text.

-- for variables the other sub "lfdshowvar" is preferable but in exceptional
-- cases it can be justified to send text with values of variables to this sub

-- no size limit

-- upvalue "qstrtrace" must NOT be type "nil" on entry (is inited to "<br>")

-- uses upvalue "qboodetrc"

local function lftracemsg (strshortline)
  if (qboodetrc and (type(strshortline)=='string')) then
    qstrtrace = qstrtrace .. strshortline .. '.<br>' -- dot added !!!
  end--if
end--function lftracemsg

------------------------------------------------------------------------

-- Local function LFDIMPORTREPORT

-- Enhance upvalue "qstrtrace" with imported report.

-- use this one to import detrc text from submodule

-- upvalue "qstrtrace" must NOT be type "nil" on entry (is inited to "<br>")

-- uses upvalue "qboodetrc"

local function lfdimportreport (strshortlineorbigtext)
  local strseparator = ''
  if (qboodetrc and (type(strshortlineorbigtext)=='string')) then
    strseparator = '<br>&#35;######################&#35;<br>'
    qstrtrace = qstrtrace .. strseparator .. strshortlineorbigtext .. strseparator .. '<br>'
  end--if
end--function lfdimportreport

------------------------------------------------------------------------

-- Local function LFDMINISANI

-- Input  : * strdangerous -- must be type "string", empty legal
--          * numlimitdivthree

-- Output : * strsanitized -- can happen to be quasi-empty with <<"">>

-- To be called from "lfdshowvcore" <- "lfdshowvar" only.

-- * we absolutely must disallow: cross "#" 35 | apo "'" 39 |
--   star "*" 42 | dash 45 | colon 58 | "<" 60 | ">" 62 | "[" 91 | "]" 93
-- * spaces are showed as "{32}" if repetitive or at begin or at end

local function lfdminisani (strdangerous, numlimitdivthree)

  local strsanitized = '"' -- begin quot
  local num38len = 0
  local num38index = 1 -- ONE-based
  local num38signo = 0
  local num38prev = 0
  local boohtmlenc = false
  local boovisienc = false

  num38len = string.len (strdangerous)
  while true do
    boohtmlenc = false -- % reset on
    boovisienc = false -- % every iteration
    if (num38index>num38len) then -- ONE-based
      break -- done string char after char
    end--if
    num38signo = string.byte (strdangerous,num38index,num38index)
    if ((num38signo<43) or (num38signo==45) or (num38signo==58) or (num38signo==60) or (num38signo==62) or (num38signo==91) or (num38signo==93) or (num38signo>122)) then
      boohtmlenc = true
    end--if
    if ((num38signo<32) or (num38signo>126)) then
      boovisienc = true -- overrides "boohtmlenc"
    end--if
    if ((num38signo==32) and ((num38prev==32) or (num38index==1) or (num38index==num38len))) then
      boovisienc = true -- overrides "boohtmlenc"
    end--if
    if (boovisienc) then
      strsanitized = strsanitized .. '{' .. tostring (num38signo) .. '}'
    else
      if (boohtmlenc) then
        strsanitized = strsanitized .. '&#' .. tostring (num38signo) .. ';'
      else
        strsanitized = strsanitized .. string.char (num38signo)
      end--if
    end--if
    if ((num38len>(numlimitdivthree*3)) and (num38index==numlimitdivthree)) then
      num38index = num38len - numlimitdivthree -- jump forwards
      strsanitized = strsanitized .. '" ... "'
    else
      num38index = num38index + 1 -- ONE-based
    end--if
    num38prev = num38signo
  end--while
  strsanitized = strsanitized .. '"' -- don't forget final quot

  return strsanitized

end--function lfdminisani

------------------------------------------------------------------------

-- Local function LFDSHOWVCORE

-- Prebrew report about content of a variable including optional full
-- listing of a table with numerical and string indexes.                        !!!FIXME!!!

-- Input  : * vardubious -- content (any type including "nil")
--          * strname -- name of the variable (string)
--          * vardescri -- optional, defa empty
--          * vartablim -- optional, defa 0, max 20

-- Depends on functions :
-- [D] lfdminisani

local function lfdshowvcore (vardubious, strname, vardescri, vartablim)

  local taballkeystring = {}
  local strtype = ''
  local strreport = ''
  local numindax = 0
  local numlencx = 0
  local numkeynumber = 0
  local numkeystring = 0
  local numkeycetera = 0
  local numkey77min = 999999
  local numkey77max = -999999

  if (type(vartablim)~='number') then
    vartablim = 0 -- deactivate listing of a table
  end--if
  if (type(vardescri)~='string') then
    vardescri = '' -- omit comment
  else
    vardescri = ' (' .. vardescri .. ')' -- augment only if used !!!
  end--if
  if (type(strname)~='string') then -- this must be below "type(vardescri)"
    strname = '??' -- bite the bullet
  else
    strname = '"' .. strname .. '"' .. vardescri -- combo
  end--if

  strtype = type(vardubious)

  if (strtype=='table') then

    for k,v in pairs(vardubious) do
      if (type(k)=='number') then
        numkey77min = math.min (numkey77min,k)
        numkey77max = math.max (numkey77max,k)
        numkeynumber = numkeynumber + 1
      else
        if (type(k)=='string') then
          taballkeystring [numkeystring] = k
          numkeystring = numkeystring + 1
        else
          numkeycetera = numkeycetera + 1
        end--if
      end--if
    end--for

    strreport = 'Table ' .. strname
    if ((numkeynumber==0) and (numkeystring==0) and (numkeycetera==0)) then
      strreport = strreport .. ' is empty'
    else
      strreport = strreport .. ' contains '
      if (numkeynumber==0) then
        strreport = strreport .. 'NO numeric keys'
      end--if
      if (numkeynumber==1) then
        strreport = strreport .. 'a single numeric key equal ' .. tostring (numkey77min)
      end--if
      if (numkeynumber>=2) then
        strreport = strreport .. tostring (numkeynumber) .. ' numeric keys ranging from ' .. tostring (numkey77min) .. ' to ' .. tostring (numkey77max)
      end--if
      strreport = strreport .. ' and ' .. tostring (numkeystring) .. ' string keys and ' .. tostring (numkeycetera) .. ' other keys'
    end--if

    if ((numkeynumber~=0) and (vartablim~=0)) then -- !!!FIXME!!!
      strreport = strreport .. ' ### content num keys :'
      numindax = numkey77min
        while true do
          if ((numindax>vartablim) or (numindax>numkey77max)) then
            break -- done table
          end--if
          strreport = strreport .. ' ' .. tostring(numindax) .. ' -> ' .. lfdminisani(tostring(vardubious[numindax]),30)
          numindax = numindax + 1
        end--while
    end--if

    if ((numkeystring~=0) and (vartablim~=0)) then -- !!!FIXME!!!
      strreport = strreport .. ' ### content string keys :'
    end--if

  else

      strreport = 'Variable ' .. strname .. ' has type "' .. strtype .. '"'
      if (strtype=='string') then
        numlencx = string.len (vardubious)
        strreport = strreport .. ' and length ' .. tostring (numlencx)
        if (numlencx~=0) then
          strreport = strreport .. ' and content ' .. lfdminisani (vardubious,30)
        end--if
      else
        if (strtype~='nil') then
          strreport = strreport .. ' and content "' .. tostring (vardubious) .. '"'
        end--if
      end--if (strtype=='string') else

  end--if (strtype=='table') else

  return strreport

end--function lfdshowvcore

------------------------------------------------------------------------

-- Local function LFDSHOWVAR

-- Enhance upvalue "qstrtrace" with report about content of a
-- variable including optional full listing of a table with numerical
-- and string indexes.                                                          !!!FIXME!!!

-- Depends on functions :
-- [D] lfdminisani lfdshowvcore

-- upvalue "qstrtrace" must NOT be type "nil" on entry (is inited to "<br>")

-- uses upvalue "qboodetrc"

local function lfdshowvar (varduubious, strnaame, vardeskkri, vartabljjm)

  if (qboodetrc) then
    qstrtrace = qstrtrace .. lfdshowvcore (varduubious, strnaame, vardeskkri, vartabljjm) .. '.<br>' -- dot added !!!
  end--if

end--function lfdshowvar

------------------------------------------------------------------------

---- MATH FUNCTIONS [E] ----

------------------------------------------------------------------------

local function mathintrange (numinpoot, numzmin, numzmax)
  numinpoot = math.floor (numinpoot) -- no transcendental
  numinpoot = math.max (numinpoot,numzmin) -- not below minimum
  numinpoot = math.min (numinpoot,numzmax) -- no trillions
  return numinpoot -- same var for input and output
end--function mathintrange

local function mathdiv (xdividens, xdivisero)
  local resultdiv = 0 -- DIV operator lacks in LUA :-(
  resultdiv = math.floor (xdividens / xdivisero)
  return resultdiv
end--function mathdiv

local function mathmod (xdividendo, xdivisoro)
  local resultmod = 0 -- MOD operator is "%" and bitwise AND operator lack too
  resultmod = xdividendo % xdivisoro
  return resultmod
end--function mathmod

------------------------------------------------------------------------

-- Local function MATHBITWRIT

-- Write bit selected by ZERO-based index assigning it to "1" or "0".

-- Depends on functions :
-- [E] mathdiv mathmod

local function mathbitwrit (numinkoming, numbityndex, boowrite)
  local numpatched = 0
  local numcountup = 0
  local numweight = 1 -- single bit value 1 -> 2 -> 4 -> 8 ...
  local boosinglebit = false
  while true do
    if ((numinkoming==0) and (numcountup>numbityndex)) then
      break -- we have run out of bits on BOTH possible sources
    end--if
    if (numcountup==numbityndex) then
      boosinglebit = boowrite -- overwrite bit
    else
      boosinglebit = (mathmod(numinkoming,2)==1) -- pick bit
    end--if
    numinkoming = mathdiv(numinkoming,2) -- shift right
    if (boosinglebit) then
      numpatched = numpatched + numweight -- add one bit rtl only if true
    end--if
    numcountup = numcountup + 1 -- count up here until we run out of bits
    numweight = numweight * 2
  end--while
  return numpatched
end--function mathbitwrit

------------------------------------------------------------------------

---- NUMBER CONVERSION FUNCTIONS [N] ----

------------------------------------------------------------------------

-- Local function LFNUMTO2DIGIT

-- Convert integer 0...99 to decimal ASCII string always 2 digits "00"..."99".

-- Depends on functions :
-- [E] mathintrange mathdiv mathmod

local function lfnumto2digit (numzerotoninetynine)
  local strtwodig = '??' -- always 2 digits
  if (mathintrange(numzerotoninetynine,0,99)==numzerotoninetynine) then
    strtwodig = tostring(mathdiv(numzerotoninetynine,10)) .. tostring(mathmod(numzerotoninetynine,10))
  end--if
  return strtwodig
end--function lfnumto2digit

------------------------------------------------------------------------

---- LOW LEVEL STRING FUNCTIONS [G] ----

------------------------------------------------------------------------

-- test whether char is an ASCII digit "0"..."9", return boolean

local function lfgtestnum (numkaad)
  local boodigit = false
  boodigit = ((numkaad>=48) and (numkaad<=57))
  return boodigit
end--function lfgtestnum

------------------------------------------------------------------------

-- test whether char is an ASCII uppercase letter, return boolean

local function lfgtestuc (numkode)
  local booupperc = false
  booupperc = ((numkode>=65) and (numkode<=90))
  return booupperc
end--function lfgtestuc

------------------------------------------------------------------------

-- test whether char is an ASCII lowercase letter, return boolean

local function lfgtestlc (numcode)
  local boolowerc = false
  boolowerc = ((numcode>=97) and (numcode<=122))
  return boolowerc
end--function lfgtestlc

------------------------------------------------------------------------

-- Local function LFGCMPSUB

-- Check whether a given substring can be found at a given
-- position in a longer string.

-- Input  : * strbig, strtiny
--          * numpossta (ZERO-based)

local function lfgcmpsub (strbig, strtiny, numpossta)
  local numlenbig = 0
  local numlentiny = 0
  local boofound = false
  numlenbig = string.len (strbig)
  numlentiny = string.len (strtiny)
  if ((numlentiny>0) and ((numpossta+numlentiny)<=numlenbig)) then
    boofound = ( strtiny == (string.sub (strbig,(numpossta+1),(numpossta+numlentiny))) )
  end--if
  return boofound
end--function lfgcmpsub

------------------------------------------------------------------------

---- UTF8 FUNCTIONS [U] ----

------------------------------------------------------------------------

-- Local function LFULNUTF8CHAR

-- Evaluate length of a single UTF8 char in octet:s.

-- Input  : * numbgoctet  -- beginning octet of a UTF8 char

-- Output : * numlen1234x -- unit octet, number 1...4, or ZERO if invalid

-- Does NOT thoroughly check the validity, looks at ONE octet only.

local function lfulnutf8char (numbgoctet)
  local numlen1234x = 0
    if (numbgoctet<128) then
      numlen1234x = 1 -- $00...$7F -- ANSI/ASCII
    end--if
    if ((numbgoctet>=194) and (numbgoctet<=223)) then
      numlen1234x = 2 -- $C2 to $DF
    end--if
    if ((numbgoctet>=224) and (numbgoctet<=239)) then
      numlen1234x = 3 -- $E0 to $EF
    end--if
    if ((numbgoctet>=240) and (numbgoctet<=244)) then
      numlen1234x = 4 -- $F0 to $F4
    end--if
  return numlen1234x
end--function lfulnutf8char

------------------------------------------------------------------------

-- Local function LFCASEREST

-- Adjust case of a single letter (restricted), only ASCII
-- plus a very limited set of 2-octet UTF8 letters. (this is REST)

-- Input  : * strucinrsut : single unicode letter (1 or 2 octet:s)
--          * booupcas    : for desired uppercase "true" and for
--                          lowercase "false"
--          * numselset   : 0 ASCII -- 2 eo -- 5 sv (value 255 NOT here)

-- Output : * strucinrsut (same var) : special value "ZZ" on failure

-- Depends on functions : (this is REST)
-- [U] lfulnutf8char
-- [G] lfgtestuc lfgtestlc
-- [E] mathdiv mathmod mathbitwrit

-- Unknown non-ASCII input strictly returns "ZZ"

-- Defined sets:
-- 2: 2 x 6 uppercase and lowercase -eo- (CX GX HX JX SX UX cx gx hx jx sx ux)
--    upper CX $0108 GX $011C HX $0124 JX $0134 SX $015C UX $016C lower +1
-- 5: 2 x 4 uppercase and lowercase -sv- (AA AE OE EE aa ae oe ee)
--    upper AE $00C4 AA $00C5 EE $00C9 OE $00D6 lower +$20

local function lfcaserest (strucinrsut, booupcas, numselset)

  local numlaengdn = 0 -- length from "string.len"
  local numchaerr = 0 -- UINT8 beginning char
  local numchaess = 0 -- UINT8 later char (BIG ENDIAN, lower value here up)
  local numchareel = 0 -- UINT8 code relative to beginning of block $00...$FF
  local numdeta = 0 -- SINT8 +32 or -32 or +1 or -1 or ZERO
  local numtheemp = 0

  local boowantlowr = false
  local booiisuppr = false
  local booiislowr = false
  local boovalid = false -- preASSume guilt

  booupcas = not (not booupcas)
  boowantlowr = (not booupcas)

  while true do -- upper fake loop (this is REST)

    numlaengdn = string.len (strucinrsut)
    if ((numlaengdn<1) or (numlaengdn>2)) then -- only 1 or 2 accepted
      break -- bad string length
    end--if
    numchaerr = string.byte (strucinrsut,1,1)
    if ((lfulnutf8char(numchaerr))~=numlaengdn) then
      break -- mismatch with length
    end--if

    if (numlaengdn==1) then
      booiisuppr = lfgtestuc(numchaerr)
      booiislowr = lfgtestlc(numchaerr)
      if (booiisuppr and boowantlowr) then
        numdeta = 32 -- ASCII UPPER->lower
      end--if
      if (booiislowr and booupcas) then
        numdeta = -32 -- ASCII lower->UPPER
      end--if
      boovalid = true
      break -- success with ASCII, almost done
    end--if

    numchaess = string.byte (strucinrsut,2,2) -- only $80 to $BF
    numchareel = (mathmod(numchaerr,4)*64) + (numchaess-128) -- 4 times 64

    if ((numselset==2) and ((numchaerr==196) or (numchaerr==197))) then -- eo
      numtheemp = mathbitwrit (numchareel,0,false) -- bad way to do AND $FE
      if ((numtheemp==8) or (numtheemp==28) or (numtheemp==36) or (numtheemp==52) or (numtheemp==92) or (numtheemp==108)) then
        booiisuppr = (numtheemp==numchareel) -- UC below and even
        booiislowr = not booiisuppr
        if (booiisuppr and boowantlowr) then
          numdeta = 1 -- UPPER->lower
        end--if
        if (booiislowr and booupcas) then
          numdeta = -1 -- lower->UPPER
        end--if
        boovalid = true
        break -- success with -eo-, almost done
      end--if
    end--if ((numselset==2) and ...

    if ((numselset==5) and (numchaerr==195)) then -- sv
      numtheemp = mathbitwrit (numchareel,5,false) -- bad way to do AND $DF
      if ((numtheemp==196) or (numtheemp==197) or (numtheemp==201) or (numtheemp==214)) then
        booiisuppr = (numtheemp==numchareel) -- UC below and bit is ZERO
        booiislowr = not booiisuppr
        if (booiisuppr and boowantlowr) then
          numdeta = 32 -- UPPER->lower
        end--if
        if (booiislowr and booupcas) then
          numdeta = -32 -- lower->UPPER
        end--if
        boovalid = true
        break -- success with -sv-, almost done
      end--if
    end--if ((numselset==5) and ...

    break -- finally to join mark -- unknown non-ASCII char is a fact :-(
  end--while -- upper fake loop -- join mark (this is REST)

  while true do -- lower fake loop (this is REST)

    if (not boovalid) then
      strucinrsut = "ZZ" -- unknown non-ASCII char
      break -- helvete
    end--if

    if (numdeta==0) then
      break -- nothing to do
    end--if

    if (numlaengdn==1) then
      strucinrsut = string.char (numchaerr + numdeta) -- no risk of carry here
      break -- done
    end--if

    strucinrsut = string.char (numchaerr) .. string.char (numchaess + numdeta)

    break -- finally to join mark
  end--while -- lower fake loop -- join mark (this is REST)

  return strucinrsut -- same var for input and output

end--function lfcaserest

------------------------------------------------------------------------

-- Local function LFUCASESTR

-- Adjust case of beginning letter or of all letters in a word or group
-- of words to upper or lower, with limited and adjustable unicode support.

-- Input  : * strenigo  : word or group of words (may be empty)
--          * boouprcas : "true" for uppercase and "false" for lowercase
--          * boodooall : "true" to adjust all letters, "false" only beginning
--          * numslsaet : 0 ASCII -- 2 eo -- 5 sv -- NOPE 255 generic

-- Depends on functions : (restricted LFCASEREST)
-- [U] lfulnutf8char lfcaserest
-- [G] lfgtestuc lfgtestlc
-- [E] mathdiv mathmod mathbitwrit

local function lfucasestr (strenigo, boouprcas, boodooall, numslsaet)

  local numlein = 0
  local numposi = 1 -- octet position ONE-based
  local numcut = 0 -- length of an UTF8 char
  local bootryadj = false -- try to adjust single char
  local strte7mp = ''
  local strelygo = ''

  boouprcas = not (not boouprcas)
  boodooall = not (not boodooall)
  numlein = string.len (strenigo)

  while true do
    if (numposi>numlein) then
      break -- done
    end--if
    bootryadj = (boodooall or (numposi==1))
    numcut = lfulnutf8char(string.byte(strenigo,numposi,numposi))
    if ((numcut==0) or ((numposi+numcut-1)>numlein)) then
      numcut = 1 -- skip ie copy one faulty octet
      bootryadj = false
    end--if
    strte7mp = string.sub (strenigo,numposi,(numposi+numcut-1)) -- 1...4 oct
    if (bootryadj) then
      -- if (numslsaet==255) then
        -- strte7mp = lfcasegene(strte7mp,boouprcas) -- (generous LFCASEGENE)
      -- else
        strte7mp = lfcaserest(strte7mp,boouprcas,numslsaet) -- (restricted LFCASEREST)
      -- end--if
    end--if
    strelygo = strelygo .. strte7mp -- this can be slow
    numposi = numposi + numcut -- done 1...4 octet:s
  end--while

  return strelygo

end--function lfucasestr

------------------------------------------------------------------------

---- HIGH LEVEL STRING FUNCTIONS [I] ----

------------------------------------------------------------------------

-- Local function LFIKATALDIGU

-- Brew cat insertion (no extra colon ":") or link to
-- appendix from 3 elements.

local function lfikataldigu (strprefixx, strkataldnomo, strhintvisi)
  local strrbkma = ''
  if (type(strhintvisi)=='string') then
    strrbkma = '[[' .. strprefixx .. ':' .. strkataldnomo .. '|' .. strhintvisi .. ']]'
  else
    strrbkma = '[[' .. strprefixx .. ':' .. strkataldnomo .. ']]'
  end--if
  return strrbkma
end--function lfikataldigu

------------------------------------------------------------------------

-- Local function LFIVALIDATELNKOADV

-- Advanced test whether a string (intended to be a language code) is valid
-- containing only 2 or 3 lowercase letters, or 2...10 char:s and with some
-- dashes, or maybe a digit in middle position or maybe instead equals to "-"
-- or "??" and maybe additionally is not included on the ban list.

-- Input  : * strqooq -- string (empty is useless and returns
--                       "true" ie "bad" but cannot cause any major harm)
--          * booyesdsh -- "true" to allow special code dash "-"
--          * booyesqst -- "true" to allow special code doublequest "??"
--          * booloonkg -- "true" to allow long codes such as "zh-min-nan"
--          * boodigit -- "true" to allow digit in middle position
--          * boonoban -- (inverted) "true" to skip test against ban table

-- Output : * booisvaladv -- true if string is valid

-- Depends on functions :
-- [G] lfgtestnum lfgtestlc

-- Depends on constants :
-- * table "contabisbanned"

-- Incoming empty string is safe but type "nil" is NOT.

-- Digit is tolerable only ("and" applies):
-- * if boodigit is "true"
-- * if length is 3 char:s
-- * in middle position

-- Dashes are tolerable (except in special code "-") only ("and" applies):
-- * if length is at least 4 char:s (if this is permitted at all)
-- * in inner positions
-- * NOT adjacent
-- * maximally TWO totally
-- There may be maximally 3 adjacent letters, this makes at least ONE dash
-- obligatory for length 4...7, and TWO dashes for length 8...10.

local function lfivalidatelnkoadv (strqooq, booyesdsh, booyesqst, booloonkg, boodigit, boonoban)

  local varomongkosong = 0 -- for check against the ban list
  local numchiiar = 0
  local numukurran = 0
  local numindeex = 0 -- ZERO-based -- two loops
  local numadjlet = 0 -- number of adjacent letters (max 3)
  local numadjdsh = 0 -- number of adjacent dashes (max 1)
  local numtotdsh = 0 -- total number of dashes (max 2)
  local booislclc = false
  local booisdigi = false
  local booisdash = false
  local booisvaladv = true -- preASSume innocence -- later final verdict here

  while true do -- fake (outer) loop

    if (strqooq=="-") then
      booisvaladv = booyesdsh
      break -- to join mark -- good or bad
    end--if
    if (strqooq=="??") then
      booisvaladv = booyesqst
      break -- to join mark -- good or bad
    end--if
    numukurran = string.len (strqooq)
    if ((numukurran<2) or (numukurran>10)) then
      booisvaladv = false
      break -- to join mark -- evil
    end--if
    if (not booloonkg and (numukurran>3)) then
      booisvaladv = false
      break -- to join mark -- evil
    end--if

    numindeex = 0
    while true do -- inner genuine loop over char:s
      if (numindeex>=numukurran) then
        break -- done -- good
      end--if
      numchiiar = string.byte (strqooq,(numindeex+1),(numindeex+1))
      booisdash = (numchiiar==45)
      booisdigi = lfgtestnum(numchiiar)
      booislclc = lfgtestlc(numchiiar)
      if (not (booislclc or booisdigi or booisdash)) then
        booisvaladv = false
        break -- to join mark -- inherently bad char
      end--if
      if (booislclc) then
        numadjlet = numadjlet + 1
      else
        numadjlet = 0
      end--if
      if (booisdigi and ((numukurran~=3) or (numindeex~=1) or (not boodigit))) then
        booisvaladv = false
        break -- to join mark -- illegal digit
      end--if
      if (booisdash) then
        if ((numukurran<4) or (numindeex==0) or ((numindeex+1)==numukurran)) then
          booisvaladv = false
          break -- to join mark -- illegal dash
        end--if
        numadjdsh = numadjdsh + 1
        numtotdsh = numtotdsh + 1 -- total
      else
        numadjdsh = 0 -- do NOT zeroize the total !!!
      end--if
      if ((numadjlet>3) or (numadjdsh>1) or (numtotdsh>2)) then
        booisvaladv = false
        break -- to join mark -- evil
      end--if
      numindeex = numindeex + 1 -- ZERO-based
    end--while -- inner genuine loop over char:s

    if (not boonoban) then -- if "yesban" then
      numindeex = 0
      while true do -- lower inner genuine loop
        varomongkosong = contabisbanned[numindeex+1] -- number of elem unknown
        if (type(varomongkosong)~="string") then
          break -- abort inner loop (then outer fake loop) due to end of table
        end--if
        numukurran = string.len (varomongkosong)
        if ((numukurran<2) or (numukurran>3)) then
          break -- abort inner loop (then outer fake loop) due to faulty table
        end--if
        if (strqooq==varomongkosong) then
          booisvaladv = false
          break -- abort inner loop (then outer fake loop) due to violation
        end--if
        numindeex = numindeex + 1 -- ZERO-based
      end--while -- lower inner genuine loop
    end--if (not boonoban) then

    break -- finally to join mark
  end--while -- fake loop -- join mark

  return booisvaladv

end--function lfivalidatelnkoadv

------------------------------------------------------------------------

-- Local function LFIFILLNAME

-- Replace placeholder "\@" "\\@" by augmented name of the caller.

-- To be called ONLY from "lfhfillsurrstrtab".

-- The name of the caller is submitted to us as a parameter thus we
-- do NOT access any constants and do NOT have to peek it either.

local function lfifillname (strmessage, strcaller)

  local strhasill = ''
  local numstrloen = 0
  local numindfx = 1 -- ONE-based
  local numcjar = 0
  local numcjnext = 0

  numstrloen = string.len (strmessage)

  while true do
    if (numindfx>numstrloen) then
      break -- empty input is useless but cannot cause major harm
    end--if
    numcjar = string.byte (strmessage,numindfx,numindfx)
    numindfx = numindfx + 1
    numcjnext = 0 -- preASSume no char
    if (numindfx<=numstrloen) then
      numcjnext = string.byte (strmessage,numindfx,numindfx)
    end--if
    if ((numcjar==92) and (numcjnext==64)) then
      strhasill = strhasill .. strcaller -- invalid input is caller's risk
      numindfx = numindfx + 1 -- skip 2 octet:s of the placeholder
    else
      strhasill = strhasill .. string.char (numcjar)
    end--if
  end--while

  return strhasill

end--function lfifillname

------------------------------------------------------------------------

-- Local function LFIKODEOSG

-- Transcode eo X-surrogates to cxapeloj in a single string (eo only).

-- Input  : * streosurr -- ANSI string (empty is useless but cannot
--                                      cause major harm)

-- Output : * strutf8eo -- UTF8 string

-- Depends on functions :
-- [E] mathdiv mathmod

-- Depends on constants :
-- * table "contabtransluteo" inherently holy

-- To be called ONLY from "lfhfillsurrstrtab".

-- * the "x" in a surr pair is case insensitive,
--   for example both "kacxo" and "kacXo" give same result
-- * avoid "\", thus for example "ka\cxo" would get converted but the "\" kept
-- * double "x" (both case insensitive) prevents conversion and becomes
--   reduced to single "x", for example "kacxxo" becomes "kacxo"

local function lfikodeosg (streosurr)

  local vareopeek = 0
  local strutf8eo = ''
  local numeoinplen = 0
  local numinpinx = 0 -- ZERO-based source index
  local numknar0k = 0 -- current char
  local numknaf1x = 0 -- next char (ZERO is NOT valid)
  local numknaf2x = 0 -- post next char (ZERO is NOT valid)
  local boonext1x = false
  local boonext2x = false
  local boosudahdone = false

  numeoinplen = string.len(streosurr)

  while true do

    if (numinpinx>=numeoinplen) then
      break
    end--if

    numknar0k = string.byte(streosurr,(numinpinx+1),(numinpinx+1))
    numknaf1x = 0 -- preASSume no char
    numknaf2x = 0 -- preASSume no char
    if ((numinpinx+1)<numeoinplen) then
      numknaf1x = string.byte(streosurr,(numinpinx+2),(numinpinx+2))
    end--if
    if ((numinpinx+2)<numeoinplen) then
      numknaf2x = string.byte(streosurr,(numinpinx+3),(numinpinx+3))
    end--if

    boonext1x = ((numknaf1x==88) or (numknaf1x==120)) -- case insensitive
    boonext2x = ((numknaf2x==88) or (numknaf2x==120)) -- case insensitive
    boosudahdone = false
    if (boonext1x and boonext2x) then -- got "xx"
      strutf8eo = strutf8eo .. string.char(numknar0k,numknaf1x) -- keep one "x" only
      numinpinx = numinpinx + 3 -- eaten 3 written 2
      boosudahdone = true
    end--if
    if (boonext1x and (not boonext2x)) then -- got yes-"x" and no-"x"
      vareopeek = contabtransluteo[numknar0k] -- UINT16 or type "nil"
      if (type(vareopeek)=='number') then
        strutf8eo = strutf8eo .. string.char(mathdiv(vareopeek,256),mathmod(vareopeek,256)) -- add UTF8 char
        numinpinx = numinpinx + 2 -- eaten 2 written 2
        boosudahdone = true
      end--if
    end--if
    if (not boosudahdone) then
      strutf8eo = strutf8eo .. string.char(numknar0k) -- copy char
      numinpinx = numinpinx + 1 -- eaten 1 written 1
    end--if

  end--while

  return strutf8eo

end--function lfikodeosg

------------------------------------------------------------------------

---- HIGH LEVEL FUNCTIONS [H] ----

------------------------------------------------------------------------

-- Local function LFHCONSTRUCTERAR

-- Input  : * numerar6code -- 1 ... 99 or 2 ... 99 invalid type ignored
--          * boopeek6it

------------------------------------------------------------------------

-- Local function LFHBREWERROR  !!!FIXME!!!

-- Depends on functions :
-- [N] lfnumto2digit
-- [E] mathintrange mathdiv mathmod

-- Depends on constants :
-- * 3 strings constrelabg constrelaen constrlaxhu
-- * table contaberaroj TWO-based (may be holy)

local function lfhbrewerror (numerrorcode)
  local vardeskrip = 0
  local strytsux = '#E'
  if (mathintrange(numerrorcode,2,99)==numerrorcode) then
    strytsux = strytsux .. lfnumto2digit(numerrorcode) .. ' '
    vardeskrip = contaberaroj[numerrorcode] -- risk of type "nil"
    if (type(vardeskrip)=='string') then
      strytsux = strytsux .. vardeskrip
    else
      strytsux = strytsux .. '??' -- no text
    end--if
  else
    strytsux = strytsux .. '??' -- no valid error code
  end--if
  strytsux = constrlaxhu .. constrelabg .. strytsux .. constrelaen .. constrlaxhu
  return strytsux
end--function lfhbrewerror

------------------------------------------------------------------------

-- Local function LFHBREWERRSM

-- Input  : * numerar8code -- 2 ... 99
--          * strsubnama -- can be omitted if no submodule
--          * numsubkodo -- 1 ... 99 invalid type ignored

------------------------------------------------------------------------

-- Local function LFHFILLSURRSTRTAB

-- Process (fill in, transcode surr) either a single string, or all string
-- items in a table (even nested) using any type of keys/indexes (such as
-- a holy number sequence and non-numeric ones). Items with a non-string
-- value are kept as-is. For filling in own name, and converting eo and
-- NOPE sv surrogates (via 3 separate sub:s).

-- Input  : * varinkommen -- type "string" or "table"
--          * varfyllo -- string, or type "nil" if no filling-in desired
--          * strlingkod -- "eo" or NOPE "sv" to convert surrogates, anything
--                          else (preferably type "nil") to skip this

-- Depends on functions :
-- [I] lfifillname (only if filling-in desired)
-- [I] lfikodeosg (only if converting of eo X-surrogates desired)
-- [I] NOPE lfikodsvsg
-- [E] mathdiv mathmod (via "lfikodeosg" and NOPE "lfikodsvsg")

-- Depends on constants :
-- * table "contabtransluteo" inherently holy (via "lfikodeosg")
-- * NOPE table "contabtranslutsv"

local function lfhfillsurrstrtab (varinkommen, varfyllo, strlingkod)

  local varkey = 0 -- variable without type
  local varele = 0 -- variable without type
  local varutmatning = 0
  local boodone = false

  if (type(varinkommen)=='string') then
    if (type(varfyllo)=='string') then
      varinkommen = lfifillname (varinkommen,varfyllo) -- fill-in
    end--if
    if (strlingkod=='eo') then
      varinkommen = lfikodeosg (varinkommen) -- surr
    end--if
    -- if (strlingkod=='sv') then
      -- varinkommen = lfikodsvsg (varinkommen) -- surr
    -- end--if
    varutmatning = varinkommen -- copy, risk for no change
    boodone = true
  end--if

  if (type(varinkommen)=='table') then
    varutmatning = {} -- brew new table
    varkey = next (varinkommen) -- try to pick 0:th (in no order) key/index
    while true do
      if (varkey==nil) then
        break -- empty table or end reached
      end--if
      varele = varinkommen[varkey] -- pick element of unknown type
      if ((type(varele)=='string') or (type(varele)=='table')) then
        varele = lfhfillsurrstrtab (varele, varfyllo, strlingkod) -- RECURSION
      end--if
      varutmatning[varkey] = varele -- write at same place in dest table
      varkey = next (varinkommen, varkey) -- try to pick next key/index
    end--while
    boodone = true
  end--if

  if (not boodone) then
    varutmatning = varinkommen -- copy as-is whatever it is
  end--if

  return varutmatning

end--function lfhfillsurrstrtab

------------------------------------------------------------------------

-- Local function LFHSEIZETEXT

-- seize text from "contabmosc", return "??" if index (string) unknown

local function lfhseizetext (straccesskey)
  local vartext = 0
  local strgoodtext = ''
  vartext = contabmosc[straccesskey]
  if (type(vartext)=='string') then
    strgoodtext = vartext
  else
    strgoodtext = '??'
  end--if
  return strgoodtext
end--function lfhseizetext

------------------------------------------------------------------------

---- VARIABLES [R] ----

------------------------------------------------------------------------

function exporttable.ek (arxframent)

  -- general unknown type

  local vartymp = 0      -- variable without type multipurpose

  -- special type "args" AKA "arx"

  local arxsomons = 0    -- metaized "args" from our own or caller's "frame"

  -- general tab

  local tablg76yleft = {}
  local tabrooteo    = {} -- from submodule

  -- general str

  local strpagenam  = "" -- "{{PAGENAME}}" o "pagenameoverridetestonly"
  local strmorfwrd  = "" -- morpheme or word extracted from pagename
  local strmorfrnd  = "" -- morpheme or word but possible leading dash removed
  local strruangna  = "" -- "{{NAMESPACENUMBER}}" o "nsnumberoverridetestonly"
  local strkodbah   = ""
  local strnambah   = "" -- language name (short without prefix "Bahasa")
  local strdetaleo  = "" -- from submodule, -eo- only so far
  local strkatojeo  = "" -- from submodule, -eo- only so far

  local strmorphdesk = "" -- description of morpheme (empty if word instead)
  local strmorfio    = "" -- with quotes and maybe link
  local strlingvoo   = "" -- big speech and cannot be empty
  local strskripto   = "" -- big speech but can also be empty

  local strtump      = "" -- temp

  local strviserr    = "" -- visible error
  local strvisgud    = "" -- visible good output
  local strinvkat    = "" -- invisible category part
  local strret       = "" -- final result string

  -- general num

  local numerr    = 0 -- 1 inter 2 param 4 ns 5 evidente 6 pagename ...
  local num2statcode = 0
  local numowntyp = 0 -- 0 invalid | 1 vorto 2 frazo 3 vortgrupo
  local nummortyp = 0 -- 0 invalid | 67 C 73 I 77 M 78 N 80 P 85 U
  local numskript = 0 -- script code, all uppercase ASCII accepted
  local numtamp   = 0

  -- general boo

  local booiskay  = false -- from "K"
  local booknown  = false -- from submodule

------------------------------------------------------------------------

---- MAIN [Z] ----

------------------------------------------------------------------------

  ---- GUARD AGAINST INTERNAL ERROR AGAIN ----

  -- later reporting of #E01 may NOT depend on uncommentable strings

  lftracemsg ('This is "mfarado", requested "detrc" report')

  if (qbooguard) then
    numerr = 1 -- #E01 internal
  end--if

  ---- PROCESS MESSAGES, FILL IN ALWAYS, SURR ONLY IF NEEDED ----

  -- placeholder "\@" "\\@" is replaced by augmented name of the caller
  -- from "constrkoll" in any case, for example 'sxablono "test"' or
  -- 'templat "test"'

  -- only for some languages the surr-transcoding is subsequently performed

  if (numerr==0) then
    contaberaroj   = lfhfillsurrstrtab (contaberaroj, constrkoll, constrpriv)
    contabboasting = lfhfillsurrstrtab (contabboasting, nil, constrpriv) -- no filling
    contabmosc     = lfhfillsurrstrtab (contabmosc, nil, constrpriv) -- no filling
  end--if

  ---- PICK ONE SUBTABLE ----

  -- on error we assign "numerr" and "num2statcode" both used far below

  while true do -- fake loop

    if (numerr~=0) then -- #E01 possible
      break -- to join mark
    end--if

    num2statcode = qldingvoj[2] -- from "loaddata-tbllingvoj"
    if (type(num2statcode)~='number') then -- important check
      numerr = 2 -- #E02 malica
      break -- to join mark
    end--if
    if (num2statcode~=0) then
      if (mathisintrange(num2statcode,2,79)) then
        numerr = 3 -- #E03 nombrigita
      else
        numerr = 2 -- #E02 malica
      end--if
      break -- to join mark
    end--if
    tablg76yleft = qldingvoj['T76']
    if (type(tablg76yleft)~='table') then -- important check
      numerr = 2 -- #E02 malica
      break -- to join mark
    end--if

    break -- finally to join mark
  end--while -- fake loop -- join mark

  lfdshowvar (numerr,'numerr','picked T76')
  lfdshowvar (num2statcode,'num2statcode')

  ---- GET THE ARX (ONE OF TWO) ----

  -- must be seized independently on "numerr" even if we already suck

  -- give a f**k in possible params other than "caller=true"

  arxsomons = arxframent.args -- "args" from our own "frame"
  if (type(arxsomons)~='table') then
    arxsomons = {} -- guard against indexing error from our own
    numerr = 1 -- #E01 internal
  end--if
  if (arxsomons['caller']=='true') then
    arxsomons = arxframent:getParent().args -- "args" from caller's "frame"
  end--if
  if (type(arxsomons)~='table') then
    arxsomons = {} -- guard against indexing error again
    numerr = 1 -- #E01 internal
  end--if

  ---- PROCESS 3 HIDDEN NAMED PARAMS ----

  -- this may override "mw.title.getCurrentTitle().text" and
  -- stipulate content in "strpagenam", empty is NOT valid

  -- bad "pagenameoverridetestonly=" can give #E01
  -- no error is possible from other hidden parameters

  -- "detrc=" must be seized independently on "numerr"
  -- even if we already suck, but type "table" must be ensured above !!!

  strpagenam = ''
  if (numerr==0) then
    vartymp = arxsomons['pagenameoverridetestonly']
    if (type(vartymp)=='string') then
      numtamp = string.len(vartymp)
      if ((numtamp>=1) and (numtamp<=120)) then
        strpagenam = vartymp -- empty is not legal
      else
        numerr = 1 -- #E01 internal
      end--if
    end--if
  end--if

  strruangna = ''
  if (numerr==0) then
    vartymp = arxsomons['nsnumberoverridetestonly']
    if (type(vartymp)=='string') then
      numtamp = string.len(vartymp)
      if ((numtamp>=1) and (numtamp<=4)) then
        strruangna = vartymp -- empty is not legal but ignore crime
      end--if
    end--if
  end--if

  if (arxsomons['detrc']=='true') then
    lftracemsg ('Param "detrc=true" seized')
  else
    qboodetrc = false -- was preassigned to "true"
    qstrtrace = '' -- shut up now
  end--if

  lfdshowvar (numerr,'numerr','done with hidden params')

  ---- SEIZE THE PAGENAME FROM MW ----

  -- later reporting of #E01 may NOT depend on uncommentable strings

  -- must be 1...120 octet:s keep consistent with "pagenameoverridetestonly="

  if ((numerr==0) and (strpagenam=='')) then
    vartymp = mw.title.getCurrentTitle().text -- without namespace prefix
    if (type(vartymp)=='string') then -- this can leave bhd "strpagenam" empty
      numtamp = string.len(vartymp)
      if ((numtamp>=1) and (numtamp<=120)) then
        strpagenam = vartymp -- pagename here (empty is NOT legal)
      else
        numerr = 1 -- #E01 internal
      end--if
    end--if
  end--if

  if (numerr==0) then
    if (strpagenam=='') then
      numerr = 1 -- #E01 internal
    end--if
  end--if

  ---- WHINE IF YOU MUST #E01 ----

  -- reporting of this error #E01 may NOT depend on
  -- uncommentable strings as "constrkoll" and "contaberaroj"

  -- do NOT use sub "lfhbrewerror", report our name (NOT of template) and in EN

  if (numerr==1) then
    strtump = '#E01 Internal error in module "mfarado".'
    strviserr = constrlaxhu .. constrelabg .. strtump .. constrelaen .. constrlaxhu
  end--if

  ---- PROCESS ANON PARAMS ----

  if (numerr==0) then
    if (arxsomons[2]~=nil) then
      numerr = 2 -- #E02 too many
    end--if
  end--if
  if (numerr==0) then
    vartymp = arxsomons[1]
    booiskay = (vartymp=='K')
    if ((not booiskay) and (vartymp~=nil)) then
      numerr = 3 -- #E03 only "K" is legal
    end--if
  end--if

  lfdshowvar (numerr,'numerr','processed anon params')
  lfdshowvar (booiskay,'booiskay')

  ---- SEIZE THE NAMESPACE FROM MW AND CHECK IT ----

  if ((numerr==0) and (strruangna=='')) then
    vartymp = mw.title.getCurrentTitle().namespace -- this is a number
    if (type(vartymp)=='number') then -- this can leave bhnd "strruangna" empty
      if ((vartymp>=0) and (vartymp<=9999)) then
        strruangna = tostring(vartymp) -- empty is not legal but ignore crime
      end--if
    end--if
  end--if

  if (numerr==0) then
    if (strruangna~='14') then
      numerr = 4 -- #E04 ns
    end--if
  end--if

  lfdshowvar (numerr,'numerr','namespace seized')
  lfdshowvar (strruangna,'strruangna')

  ---- DISSECT THE PAGENAME ----

  -- There are 3 possible types:
  -- * "Vorto -en- enhavanta morfemon U (-ist)" 1
  -- * "Frazo -en- enhavanta vorton (nope)" 2
  -- * "Vortgrupo -en- enhavanta (nope)" 3
  -- There can follow 2 more char:s namely space and script code.

  -- All cat:s will later receive the same sorting hint ... if the morpheme
  -- or word begins with a dash then remove it so that "-o" falls under "O"
  -- instead of under "-" ... still keep possible irrelevant trailing dash.

  nummortyp = 0
  numskript = 0

  do -- scope
    local numlong   = 0 -- length of pagename
    local numposnam = 0 -- pos in pagename
    local numoct    = 0
    local numodt    = 0
    local numlenko  = 0 -- 0...10 only but ZERO and ONE invalid soon later
    local numtymp   = 0

    while true do -- outer fake loop

      if (numerr~=0) then
        break
      end--if

    numlong = string.len (strpagenam)
    numowntyp = 0 -- 0 invalid | 1 vorto 2 frazo 3 vortgrupo
    if (lfgcmpsub(strpagenam,"Vorto -",0)) then
      numowntyp = 1
      numposnam = 7
    end--if
    if (lfgcmpsub(strpagenam,"Frazo -",0)) then
      numowntyp = 2
      numposnam = 7
    end--if
    if (lfgcmpsub(strpagenam,"Vortgrupo -",0)) then
      numowntyp = 3
      numposnam = 11
    end--if
    if (numowntyp==0) then
      numerr = 10 -- #E10 none of 3 supported types
      break
    end--if

    lfdshowvar (numowntyp,'numowntyp','after first ONE-of-THREE validation step')

    strkodbah = '' -- read char by char until "- " DASHSPACE reached or error
    numlenko = 0 -- valid values are 2...10 but later further checks follow
    while true do -- inner genuine loop
      if ((numposnam+1)>=numlong) then -- "numposnam" is ZERO-based
        numerr = 11 -- #E11 truncated incoming string
        break
      end--if
      numposnam = numposnam + 1 -- INC-before-pick compensates for ONE-based
      numoct = string.byte (strpagenam,(numposnam  ),(numposnam  ))
      numodt = string.byte (strpagenam,(numposnam+1),(numposnam+1))
      if ((numoct==45) and (numodt==32)) then
        numposnam = numposnam + 1 -- jump over the space too
        break -- found "- "
      end--if
      if (numlenko>=10) then
        numerr = 11 -- #E11 too long monstercode "zh-min-nan-max" :-D
        break
      end--if
      strkodbah = strkodbah .. string.char(numoct)
      numlenko = numlenko + 1
    end--while -- inner genuine loop
    if (numerr~=0) then
      break -- do not forget to exit outer loop too
    end--if

    lftracemsg ('Lang code (extraction up to 10, not yet validated) is "' .. strkodbah .. '"')

    if (not lfivalidatelnkoadv(strkodbah,false,false,conbookodlng,conboomiddig,false)) then
      numerr = 5 -- #E05 bad lang code
      break
    end--if

    lftracemsg ('The lang code is valid')

    numtymp = 0
    if (numowntyp==1) then
      if (lfgcmpsub(strpagenam,"enhavanta morfemon ",numposnam)) then
        numtymp = 19
      end--if
    end--if
    if (numowntyp==2) then
      if (lfgcmpsub(strpagenam,"enhavanta vorton ",numposnam)) then
        numtymp = 17
      end--if
    end--if
    if (numowntyp==3) then
      if (lfgcmpsub(strpagenam,"enhavanta ",numposnam)) then
        numtymp = 10
      end--if
    end--if
    if (numtymp==0) then
      numerr = 11 -- #E11 not found
      break
    end--if
    numposnam = numposnam + numtymp -- jump over it

    lftracemsg ('After second ONE-of-THREE validation step')

    if (numowntyp==1) then
      if ((numposnam+2)>numlong) then -- "numposnam" is ZERO-based
        numerr = 11 -- #E11 truncated
        break
      end--if
      nummortyp = string.byte (strpagenam,(numposnam+1),(numposnam+1))
      numodt = string.byte (strpagenam,(numposnam+2),(numposnam+2))
      if ((nummortyp~=67) and (nummortyp~=73) and (nummortyp~=77) and (nummortyp~=78) and (nummortyp~=80) and (nummortyp~=85)) then
        numerr = 11 -- #E11 invalid code
        break
      end--if
      if (numodt~=32) then
        numerr = 11 -- #E11 no space char
        break
      end--if
      numposnam = numposnam + 2 -- jump over uppercase code and space

      lftracemsg ('Seized "mortyp", it is ' .. tostring(nummortyp))

    end--if

    if ((numposnam+3)>numlong) then -- "numposnam" is ZERO-based
      numerr = 11 -- #E11 truncated (two brackets plus min length one -> 3)
      break
    end--if
    numoct = string.byte (strpagenam,(numlong-1),(numlong-1))
    numodt = string.byte (strpagenam, numlong,    numlong   )
    if ((numoct==32) and lfgtestuc(numodt)) then
      numskript = numodt
      numlong = numlong - 2 -- trim it off

      lftracemsg ('Seized script code, it is ' .. tostring(numskript))

    end--if

    numoct = string.byte (strpagenam,(numposnam+1),(numposnam+1))
    numodt = string.byte (strpagenam,numlong,numlong)
    if ((numoct~=40) or (numodt~=41)) then
      numerr = 11 -- #E11 need "(" and ")"
      break
    end--if
    strmorfwrd = string.sub (strpagenam,(numposnam+2),(numlong-1)) -- extract

    numoct = string.byte (strmorfwrd,1,1)
    if (numoct==45) then
      strmorfrnd = string.sub (strmorfwrd,2,-1) -- remove Boulder Dash
    else
      strmorfrnd = strmorfwrd -- copy
    end--if

      lfdshowvar (strmorfwrd,'strmorfwrd','extracted morpheme or word')
      lfdshowvar (strmorfrnd,'strmorfrnd','without dash')

      break -- finally to join mark
    end--while -- outer fake loop -- join mark

  end--do scope

  lfdshowvar (numerr,'numerr','after dissection')

  ---- WHINE IF YOU MUST #E02...#E99 ---- !!!FIXME!!!

  if (numerr>1) then
    strviserr = lfhbrewerror(numerr)
  end--if

  -- if (numerr>1) then
  --   if (numerr==3) then -- #E03
  --     strviserr = lfhbrewerrsm(numerr,constringvoj,num2statcode) -- 2 lines
  --   else
  --     strviserr = lfhbrewerrsm(numerr) -- 1 line
  --   end--if
  -- end--if

  ---- PEEK LANG NAME ----

  -- x-index is /c0/ for lang name in site language but no need for it in T76

  if (numerr==0) then
    strnambah = tablg76yleft[strkodbah]
    booknown = (type(strnambah)=='string') and (strnambah~='-') and (strnambah~='=') -- "false" is criminal
  end--if

  lfdshowvar (numerr,'numerr','after peeking lang name')
  lfdshowvar (strnambah,'strnambah')

  ---- PEEK DETAILS VIA SUBMODULE IF ONLY 4 + 1 CONDITIONS ARE MET ----

  -- submodule "rooteo" requires two named
  -- parameters "in=" and "givetable=true"

  -- returned table has elements 0...4 :
  -- 0 error code (ZERO OK)
  -- 1 strvisgud
  -- 2 strinvkat
  -- 3 strvisred -- we use this reduced text
  -- 4 qstrtrace

  -- Examples of full and reduced text:
  -- * <<La elemento "mov" (tipo N) troveblas en BRO5 kaj OA6.>>
  --                              <<troveblas en BRO5 kaj OA6>>
  -- * <<La elemento "-unt-" (tipo
  --   I) ne troveblas en iu listo kaj do estas neoficiala.>>
  --    <<ne troveblas en iu listo kaj do estas neoficiala>>

  strdetaleo = '' -- later concat:ed if non-empty
  strkatojeo = '' -- later concat:ed in any case, but can be empty

  if ((numerr==0) and (numowntyp==1) and (strkodbah=='eo') and conboouseeox) then

    if (booiskay) then

      strkatojeo = lfikataldigu(constrkatq,contabboasting[10],strmorfrnd) -- got bad "K" but remaining 4 are met

    else

      strtump = '' -- preASSume
      if (qboodetrc) then
        strtump = 'true' -- also from submodule
      end--if
      tabrooteo = qeorooteo.ek { args = { ['in']=strpagenam , ['givetable']='true' , ['detrc']=strtump } }
      if (type(tabrooteo)=='table') then
        numtamp = tabrooteo[0]
        if (numtamp==0) then
          strdetaleo = tabrooteo[3] -- reduced
          strkatojeo = tabrooteo[2]
        else
          numerr = numtamp + 20 -- #E21 and higher
        end--if
        if (qboodetrc) then
          lfdimportreport (tabrooteo[4]) -- import it
        end--if
      else
        numerr = 12 -- #E12
      end--if

    end--if (booiskay) else

  end--if ((numerr==0) and (numowntyp==1) and ...

  lfdshowvar (numerr,'numerr','submodule "rooteo" maybe called')
  lfdshowvar (strdetaleo,'strdetaleo')
  lfdshowvar (strkatojeo,'strkatojeo')

  ---- PREBREW DESCRIPTION OF MORPHEME ----

  -- "nummortyp" -- 0 invalid | 67 C 73 I 77 M 78 N 80 P 85 U

  -- incoming from above "strdetaleo" (empty if not applicable)

  -- note that "booiskay" from "K" and "strdetaleo" exclude
  -- each other but they can even be both absent

  -- after this block the text fragment in "strmorphdesk" will either
  -- * begin with a space and end with either a word or a
  --   closing arc bracket ")" (NOT a space in any case)
  -- or
  -- * be empty

  strmorphdesk = ''
  if ((numerr==0) and (numowntyp==1)) then

    do -- scope
    local strpriskribo = '' -- 1 of 6 values from "nummortyp"
    local strmortypletter = ''

    strmortypletter = string.char (nummortyp)
    strpriskribo = lfhseizetext (strmortypletter) -- letter to word
    if (booiskay) then
      strpriskribo = strpriskribo .. ' kunmetitan' -- "contabmosc" also accusa
    end--if
    if (strdetaleo~='') then
      strpriskribo = strpriskribo .. ', ' .. strdetaleo
    end--if
    strmorphdesk = ' ' .. strmortypletter .. ' (' .. strpriskribo .. ')'

    end--do scope

  end--if

  ---- PREBREW STUFF AND LINK TO APPENDIX PAGE AND SCRIPT DETAILS ----

  -- "strmorfwrd" contains the raw morpheme or word but dashes can persist
  -- "strmorfrnd" is without leading dash

  -- string "constrapxq" is appendix prefix and excludes the colon ":"

  -- this outputs 3 fragments:
  -- * trivial "strmorfio" no spaces
  -- * intricate "strlingvoo" begins with space ends with arc bracket ")"
  -- * medium "strskripto" begins with space ends with arc bracket ")"

  if (numerr==0) then

    do -- scope
      local straldono = '' -- link or not and cannot be empty
      local strlngandskr = '' -- "jaH"

      if (nummortyp==78) then -- "N"
        strmorfio = '"' .. strmorfwrd .. '"' -- do NOT link nonstandalone roots
      else
        strmorfio = '"[[' .. strmorfwrd .. ']]"'
      end--if
      if (booknown) then
        straldono = 'la lingvo ' .. lfikataldigu(constrapxq,(lfucasestr(strnambah,true,false,2)),strnambah)
      else
        straldono = 'nekonata lingvo'
      end--if
      strlingvoo = ' en '.. straldono .. ' (lingvokodo -' .. strkodbah .. '-)'
      if (booknown and (numskript~=0)) then
        strlngandskr = strkodbah .. string.char (numskript) -- gives fe "jaH"
        strskripto = ' per la skribo ' .. string.char (numskript) .. ' (' .. lfhseizetext (strlngandskr) .. ')'
      else
        strskripto = ''
      end--if

    end--do scope

  end--if

  ---- BREW THE VISIBLE BOX PART ----

  -- "numowntyp" -- 0 invalid | 1 vorto 2 frazo 3 vortgrupo

  -- text in "contabboasting" ends with a word (not space)

  if (numerr==0) then
    strvisgud = contabhtml[0] .. contabhtml[1] .. contabboasting [numowntyp] .. strmorphdesk .. ' ' .. strmorfio .. strlingvoo .. strskripto .. '.' .. contabhtml[2]
  end--if

  ---- BREW THE INVISIBLE CATEGORY PART ----

  -- incoming from above "strkatojeo" (empty if not applicable)

  -- "strmorfwrd" contains the raw morpheme or word but dashes can persist
  -- "strmorfrnd" is without leading dash

  -- string "constrkatq" is cat prefix and excludes the colon ":"

  -- brew "__HIDDENCAT__" as well as 2 cat insertions (not if lang code
  -- is unknown) and possibly further ones from submodule or "K" (if -eo-)

  -- the cat:s are for example "Vortfarado|"... and "Vortfarado (angla)|"...

  if (numerr==0) then
    strinvkat = '__HIDDENCAT__' .. strkatojeo
    if (booknown) then
      strinvkat = strinvkat .. lfikataldigu(constrkatq,'Vortfarado',strmorfrnd)
      strinvkat = strinvkat .. lfikataldigu(constrkatq,('Vortfarado (' .. strnambah .. ')'),strmorfrnd)
    end--if
  end--if

  ---- RETURN THE JUNK STRING ----

  strret = strviserr .. strvisgud .. strinvkat
  if (qboodetrc) then -- "qstrtrace" declared separately outside main function
    strret = "<br>" .. qstrtrace .. "<br><br>" .. strret
  end--if
  return strret

end--function

  ---- RETURN THE JUNK LUA TABLE ----

return exporttable