Modulo:mchklngcode
Salti al navigilo
Salti al serĉilo
dokumentaĵo: redakti · aktualigi
modulo: subpaĝoj · uzata en ŝablonoj · uzata en moduloj
- Pri la modulo kontaktu Uzanto:Taylor_49
|
Memtesto disponeblas sur la dokumentaĵa subpaĝo |
--[===[
MODULE "MCHKLNGCODE" (check language code)
"eo.wiktionary.org/wiki/Modulo:mchklngcode" <!--2020-Nov-xx-->
"id.wiktionary.org/wiki/Modul:mchklngcode"
Purpose: checks validity of 1 or 2 parameters that are supposed to
contain language code in 2 stages: by testing whether they
are obviously invalid, and if this does not apply whether
they are known
Utilo: kontrolas validecon de 1 aux 2 parametroj kiuj enhavu
lingvokodon en 2 pasxoj: testante cxu ili estas evidente
nevalidaj, kaj se tio ne veras cxu ili estas konataj
Manfaat: mengontrol validitas 1 atau 2 parameter yang seharusnya
berisi kode bahasa ...
Syfte: kontrollerar giltighet av 1 eller 2 parametrar som ska innehaalla
spraakkod ...
Used by templates / Uzata far sxablonoj:
- deveno3 elpropra Lingvo t
Required submodules / Bezonataj submoduloj / Submodul yang diperlukan:
- "mpiktbllki" in turn requiring "mbllingvoj" (EO) or "mtblbahasa" (ID)
- "mbllingvoj" in turn requiring template "tbllingvoj" (EO)
- "mtblbahasa" in turn requiring template "tblbahasa" (ID)
This module is special in that it takes parameters both those sent
to itself (own frame) and those sent to the caller (caller's frame).
This module needs parameters that are different from parameters
submitted to the calling template.
Incoming: - 1 or 2 anonymous parameters
- 1 or 2 parameters forwarded from the caller using "{{{1}}}"
or "{{{ling}}}" or similarly, wall "|" is not needed,
maybe "{{{ling|eo}}}" for an optional parameter,
conversely "{{{ling|}}}" is bad
- 1 optional named parameter
- "xx=" tuning string with 5 char:s (one tristate letter,
3 bool digits "0" or "1", and one four-state digit)
- tri-state letter : desired type of result (default is "b"):
- "b" -- bool (0 evil -- 1 tolerable) for conditional logic
in classic templates ("evil" is invalid,
"tolerable" is unknown or known)
- "t" -- tristate (0 invalid -- 1 unknown -- 2 known)
- "k" -- category (2 categories without EOL between them
if applicable, or empty string if known, see below)
- bool: do check 2 codes (by default only 1 code is checked)
- 4-state digit: allow "-" or "??" (default "0" ie NOT allow)
- "0" -- do not allow any
- "1" -- allow "-"
- "2" -- allow "??"
- "3" -- allow both
- bool: allow digit in middle position of 3-letter codes
("t8i") (default false ie NOT allow)
- bool: do NOT disallow some common bad codes ("epo",
"por", ...) by ban table (default false ie disallow)
Parameters accepted from both own and caller's frame:
- 2 named optional hidden parameters
- "debug=true" (dec-encode the output and that way make the
category links on error visible, any other value is ignored)
- "nocat=true" (suppress categorization in "k" mode,
any other value is ignored, also ignored if "debug=true"
since "debug" overrides "nocat")
Returned: - "b" : string "1" if the parameters/codes are tolerable (known or
unknown), string "0" if the parameters/codes are evil
(obviously invalid), or this module itself becomes
victim of misuse
- "t" : string "2" if the parameters/codes are known (both known),
string "1" if the parameters/codes are unknown but not
obviously invalid, string "0" if the parameters/codes
are invalid (at least one is obviously invalid), or this
module itself becomes victim of misuse
- "k" : up to 3 categories (of 2 possible types) without EOL between
them, or empty string if the parameters are accepted,
no junk categories if this module itself becomes
victim of misuse
For "b" and "t" the principle is "the worst result counts", but for "k"
the 2 triples of categories are based on separate evaluations of the 2 codes.
The validity check for obviously invalid code
requires in order to return result "pass":
- must be 2 or 3 ASCII char:s long
- must consist of lowercase letters only (optionally,
digit in the middle position can be allowed)
- must not be on the ban list (this check can optionally be deactivated)
- optionally string "-" or "??" (but not "???") can be allowed in this
stage (but still cannot be accepted later as "known")
La kontrolo pri evidente nevalida kode postulas
por redoni rezulton "tolerebla":
- longo estu 2 aux 3 ASCII signoj
- enhavu nur minusklajn literojn (opcie, cifero povas
esti permesita en la meza pozicio)
- ne trovigxu sur la forbara listo (cxi tiu kontrolo povas opcie
esti senaktivigita)
- opcie signocxeno "-" aux "??" (sed ne "???") povas esti permesita en cxi tiu
pasxo (sed dauxre ne povas esti akceptita pli tarde kiel "konata")
Note that the operation modes "b" or "t" and on the other side "k" are
separated and it is NOT possible to merge them. Result from "b" is fed into
"#ifeq" and possible categories would be ignored. Thus this module will be
usually called several times from one template, even with same language code.
Note that the result in bool mode "b" is either "1" "accepted" or "0" "bad"
after this module has succeeded to run. But there is a third option "module
failed to run" due to not found or timeout for example. The conditional logic
in the calling template must be aware of this.
In the category mode "k" the format of the categories is:
- obviously invalid:
- "[[Kategorio:Evidente nevalida lingvokodo]]"
- "[[Kategorio:Evidente nevalida lingvokodo nome (Deutsch)]]"
- "[[Kategorio:Evidente nevalida lingvokodo loke (deveno3)]]"
or
- uknown
- "[[Kategorio:Nekonata lingvokodo]]"
- "[[Kategorio:Nekonata lingvokodo nome (haw)]]"
- "[[Kategorio:Nekonata lingvokodo loke (deveno3)]]"
The reported detail string is sanitized for both incoming lng code
and peeked template name:
- replaced with "e-m-p-t-y" if empty
- otherwise truncated to max 14 octet:s and unsafe char:s are
replaced with dot:s (safe are "0"..."9" "A"..."Z" "a"..."z"
"!" "," "-")
There is no need to sanitize the code if it is only "unknown" (but
not obviously invalid) (but we do it).
The name of the caller ie parent ie previous page in the calling chain
(presumably a template) is peeked automatically and only the core (without
namespace prefix) is taken. Note that this is NOT the same as "{{PAGENAME}}"
returning the very last page in calling chain (presumably in NS ZERO).
If two codes are tested then two separate triples of categories can be
created of same type or of different types (one invalid and one unknown).
This module allows to mostly separate cases of "obviously invalid language
code" (for example "" (empty), "...", "Deutsch", "De", "FR", "taja", ...)
from "unknown language code" (for example "haw" that is valid according to
"ISO 639-3:2007" but might lack in the list of languages)
: ---------------------------------------
* #T00 (no params, evil)
* expected result: "0" (evil)
* actual result: "{{#invoke:mchklngcode|ek}}"
:* #T01 ("eo", default binary output, only 1 code is tested)
:* expected result: "1" (tolerable)
:* actual result: "{{#invoke:mchklngcode|ek|eo}}"
* #T02 ("eo|crap", default binary output, only 1 code is tested)
* expected result: "1" (tolerable)
* actual result: "{{#invoke:mchklngcode|ek|eo|crap}}"
:* #T03 ("eo|sv|id", 3 anon params, evil)
:* expected result: "0" (evil)
:* actual result: "{{#invoke:mchklngcode|ek|eo|sv|id}}"
* #T04 ("eo|xx=b0000", all 5 defaults explicitely confirmed, binary output)
* expected result: "1" (tolerable)
* actual result: "{{#invoke:mchklngcode|ek|eo|xx=b0000}}"
:* #T05 ("eo|xx=b00000", parameter too long)
:* expected result: "0" (bad)
:* actual result: "{{#invoke:mchklngcode|ek|eo|xx=b00000}}"
* #T06 ("eo|xx=b0020", invalid digit "2")
* expected result: "0" (bad)
* actual result: "{{#invoke:mchklngcode|ek|eo|xx=b0020}}"
:* #T07 ("eo|crap|xx=b1000", both codes are tested)
:* expected result: "0" (bad)
:* actual result: "{{#invoke:mchklngcode|ek|eo|crap|xx=b1000}}"
: ---------------------------------------
* #T10 ("eo|haw|xx=b1000", both codes are tested)
* expected result: "1" (good)
* actual result: "{{#invoke:mchklngcode|ek|eo|haw|xx=b1000}}"
:* #T11 ("eo|??|xx=b1000", both codes are tested, "??" prohibited)
:* expected result: "0" (bad)
:* actual result: "{{#invoke:mchklngcode|ek|eo|??|xx=b1000}}"
* #T12 ("eo|??|xx=b1200", both codes are tested, "??" allowed)
* expected result: "1" (good)
* actual result: "{{#invoke:mchklngcode|ek|eo|??|xx=b1200}}"
:* #T13 ("por|xx=b0000", binary output, "por" expl prohibited)
:* expected result: "0" (evil)
:* actual result: "{{#invoke:mchklngcode|ek|por|xx=b0000}}"
* #14 ("por|xx=b0001", binary output, "por" allowed)
* expected result: "1" (tolerable)
* actual result: "{{#invoke:mchklngcode|ek|por|xx=b0001}}"
* #15 ("eo|z|xx=b1101", both codes are tested, right "z" is bad)
* expected result: "0" (evil)
* actual result: "{{#invoke:mchklngcode|ek|eo|z|xx=b1101}}"
* #16 ("z|eo|xx=b1101", both codes are tested, left "z" is bad)
* expected result: "0" (evil)
* actual result: "{{#invoke:mchklngcode|ek|z|eo|xx=b1101}}"
* #17 ("epo|eo|xx=b1101", both codes are tested, "epo" allowed)
* expected result: "1" (tolerable)
* actual result: "{{#invoke:mchklngcode|ek|epo|eo|xx=b1101}}"
: ---------------------------------------
* #20 ("|ek|id||xx=b1101", both codes are tested, empty is bad)
* expected result: "0" (bad)
* actual result: "{{#invoke:mchklngcode|ek|id||xx=b1101}}"
* #21 ("|ek|id||xx=b0101", only one code is tested, empty is bad but ignored)
* expected result: "1" (good)
* actual result: "{{#invoke:mchklngcode|ek|id||xx=b0101}}"
* #22 ("|ek||id|xx=b0101", only one code is tested, empty is bad)
* expected result: "0" (bad)
* actual result: "{{#invoke:mchklngcode|ek||id|xx=b0101}}"
* #23 ("|ek|t8i|xx=b0000", digits prohibited as default)
* expected result: "0" (bad)
* actual result: "{{#invoke:mchklngcode|ek|t8i|xx=b0000}}"
* #24 ("|ek|t8i|xx=b0010", digits permitted)
* expected result: "1" (good)
* actual result: "{{#invoke:mchklngcode|ek|t8i|xx=b0010}}"
: ---------------------------------------
* #30 ("grc|xx=t0000", tristate)
* expected result: "2" (good and known)
* actual result: "{{#invoke:mchklngcode|ek|grc|xx=t0000}}"
* #31 ("t8i|xx=t0010", tristate, digits permitted)
* expected result: "2" (good and known) or "1" (valid but unknown)
* actual result: "{{#invoke:mchklngcode|ek|t8i|xx=t0010}}"
* #32 ("??|xx=t0200", tristate, "??" is allowed)
* expected result: "1" (valid but unknown)
* actual result: "{{#invoke:mchklngcode|ek|??|xx=t0200}}"
* #33 ("???|xx=t0200", tristate, "??" is allowed but "???" is NOT)
* expected result: "0" (obviously invalid)
* actual result: "{{#invoke:mchklngcode|ek|???|xx=t0200}}"
* #34 ("fra|xx=t0000", tristate, this code is expl banned)
* expected result: "0" (obviously invalid)
* actual result: "{{#invoke:mchklngcode|ek|fra|xx=t0000}}"
* #35 ("fra|xx=t0001", tristate, this code is expl banned but we do not care)
* expected result: "1" (valid but unknown)
* actual result: "{{#invoke:mchklngcode|ek|fra|xx=t0001}}"
: ---------------------------------------
* #40 ("f3i|xx=t0000", tristate, digits prohibited by default)
* expected result: "0" (obviously invalid)
* actual result: "{{#invoke:mchklngcode|ek|f3i|xx=t0000}}"
* #41 ("f3i|xx=t0010", tristate, digits permitted)
* expected result: "1" (valid but unknown)
* actual result: "{{#invoke:mchklngcode|ek|f3i|xx=t0010}}"
* #42 ("fi3|xx=t0010", tristate, digits permitted but only in middle position)
* expected result: "0" (obviously invalid)
* actual result: "{{#invoke:mchklngcode|ek|fi3|xx=t0010}}"
* #43 ("3fi|xx=t0010", tristate, digits permitted but only in middle position)
* expected result: "0" (obviously invalid)
* actual result: "{{#invoke:mchklngcode|ek|3fi|xx=t0010}}"
: ---------------------------------------
* #50 ("grc|xx=k0000", 4 defaults explicitely confirmed, category mode)
* expected result: "" (empty string, good)
* actual result: "{{#invoke:mchklngcode|ek|grc|xx=k0000}}"
* #51 ("fri|xx=k0000|debug=true", 4 defaults explicitely confirmed, category mode)
* expected result: N/A (valid but unknown, categories)
* actual result: "{{#invoke:mchklngcode|ek|fri|xx=k0000|debug=true}}"
* #52 ("fori|xx=k0000|debug=true", 4 defaults explicitely confirmed, category mode)
* expected result: N/A (obviously invalid, categories)
* actual result: "{{#invoke:mchklngcode|ek|fori|xx=k0000|debug=true}}"
<pre>
* #53 ("fri|xx=k0000", 4 defaults explicitely confirmed, category mode)
* expected result: N/A (valid but unknown, categories)
* actual result: "{{#invoke:mchklngcode|ek|fri|xx=k0000}}"
* #54 ("fori|xx=k0000", 4 defaults explicitely confirmed, category mode)
* expected result: N/A (obviously invalid, categories)
* actual result: "{{#invoke:mchklngcode|ek|fori|xx=k0000}}"
</pre>
* note that tests #53 and #54 cannot be executed on the docs subpage
: ---------------------------------------
]===]
local chklngcode = {}
------------------------------------------------------------------------
---- CONSTANTS ----
------------------------------------------------------------------------
-- ban list (only 3-letter codes, maybe also bad 2-letter codes)
-- length of the list is NOT stored anywhere, the processing stops when "nil" comes
local contabisbanned = {}
contabisbanned = {'deu','eng','epo','fra','lat','por','rus','spa','swe'} -- 1...9
-- constant strings EO vs ID
local constrplki = "Modulo:mpiktbllki" -- EO
-- local constrplki = "Modul:mpiktbllki" -- ID
local constrneva = "Kategorio:Evidente nevalida lingvokodo" -- EO -- no brackets ("[[","]]") here
-- local constrneva = "Kategori:Kode bahasa jelas-jelas tidak valid" -- ID -- no brackets ("[[","]]") here
local constrneko = "Kategorio:Nekonata lingvokodo" -- EO -- no brackets ("[[","]]") here
-- local constrneko = "Kategori:Kode bahasa tidak diketahui" -- ID -- no brackets ("[[","]]") here
-- emergency brake (6 binary digits: nevagene,nevanome,nevaloke,nekogene,nekonome,nekoloke)
local constrfilter = "111111" -- change one or several digits to ZERO to prevent categorization
------------------------------------------------------------------------
---- IMPORTS ----
------------------------------------------------------------------------
local piktbllki = require(constrplki) -- can crash here
------------------------------------------------------------------------
---- ORDINARY LOCAL MATH FUNCTIONS ----
------------------------------------------------------------------------
local function mathmin (xminaa, xminbb)
local resultmin = 0 -- min operator lacks in LUA :-(
resultmin = xminaa
if (resultmin>xminbb) then
resultmin = xminbb
end--if
return resultmin
end--function mathmin
------------------------------------------------------------------------
---- ORDINARY LOCAL LOW LEVEL FUNCTIONS ----
------------------------------------------------------------------------
-- Local function LFDECENCODE
-- Our cool module has brewed something with "[["..."]]" but we want
-- to see plain text for debugging purposes. Thus we dec-encode it.
local function lfdecencode (strkrampoj)
local strcod = ""
local numstrlen = 0
local numpeekinx = 1 -- ONE-based index
local numchar = 0
numstrlen = string.len (strkrampoj)
while (true) do
if (numpeekinx>numstrlen) then
break
end--if
numchar = string.byte (strkrampoj,numpeekinx,numpeekinx)
numpeekinx = numpeekinx + 1
strcod = strcod .. "&#" .. tostring (numchar) .. ";"
end--while
return strcod
end--function lfdecencode
------------------------------------------------------------------------
---- ORDINARY LOCAL HIGH LEVEL FUNCTIONS ----
------------------------------------------------------------------------
-- Local function LFFIXUNSAFE
-- Fix obviously invalid language code so that it can at least be used
-- inside name of a tracking category
-- # empty string replaced with "e-m-p-t-y"
-- # truncated to 14 octet:s if longer
-- # unsafe char:s are replaced with dot:s (safe are only "0"..."9" and
-- "A"..."Z" and "a"..."z" and "!" and "," and "-" and maybe ".")
-- Input : - strbahaya
-- Output : - strfixed
-- We need function "mathmin"
local function lffixunsafe (strbahaya)
local strfixed = ""
local numlencx = 0
local numcxaar = 0
local numuindex = 1 -- ONE-based
local boogood = false
if (strbahaya=="") then
strfixed = "e-m-p-t-y"
else
numlencx = mathmin (string.len (strbahaya), 14)
while (true) do
if (numuindex>numlencx) then
break
end--if
numcxaar = string.byte (strbahaya,numuindex,numuindex)
boogood = false
if ((numcxaar>=48) and (numcxaar<=57)) then
boogood = true -- 0...9
end--if
if ((numcxaar>=65) and (numcxaar<=90)) then
boogood = true -- A...Z
end--if
if ((numcxaar>=97) and (numcxaar<=122)) then
boogood = true -- a...z
end--if
if (numcxaar==33) then
boogood = true -- "!"
end--if
if ((numcxaar>=44) and (numcxaar<=46)) then
boogood = true -- ",-" -- FYI: 46 is the dot "."
end--if
if (boogood==false) then
numcxaar = 46 -- replace by dot "."
end--if
strfixed = strfixed .. string.char (numcxaar)
numuindex = numuindex + 1
end--while
end--if
return strfixed
end--function lffixunsafe
------------------------------------------------------------------------
-- Local function LFCHKKODIV
-- Check whether a string contains only 2 or 3 lowercase letters
-- or maybe digit in middle position or maybe instead equals "-" or "??" or
-- maybe additionally is not included on the ban list
-- Input : - strqooq -- string (empty is useless and returns
-- "true" ie "bad" but can't cause any harm)
-- - numnokod -- "0" ... "3" how special codes "-" "??" should pass
-- - boodigit -- "true" to allow digit in middle position
-- - boonoban -- "true" to skip test against ban table
-- Output : - booisbadlk -- bool "true" if the string is evil
-- needs const table "contabisbanned"
local function lfchkkodiv (strqooq, numnokod, boodigit, boonoban)
local varomongkosong = "" -- for check against the ban list
local booisbadlk = false
local numchiiar = 0
local numukurran = 0
local numindeex = 0 -- ZERO-based
while (true) do -- fake (outer) loop
if ((strqooq=="-") and ((numnokod==1) or (numnokod==3))) then
break -- to join mark
end--if
if ((strqooq=="??") and ((numnokod==2) or (numnokod==3))) then
break -- to join mark
end--if
numukurran = string.len (strqooq)
if ((numukurran<2) or (numukurran>3)) then
booisbadlk = true
break -- to join mark
end--if
numchiiar = string.byte (strqooq,1,1)
if ((numchiiar<97) or (numchiiar>122)) then
booisbadlk = true
break -- to join mark
end--if
numchiiar = string.byte (strqooq,numukurran,numukurran)
if ((numchiiar<97) or (numchiiar>122)) then
booisbadlk = true
break -- to join mark
end--if
if (numukurran==3) then
numchiiar = string.byte (strqooq,2,2)
if ((boodigit==false) or ((numchiiar<48) or (numchiiar>57))) then
if ((numchiiar<97) or (numchiiar>122)) then
booisbadlk = true
break -- to join mark
end--if
end--if ((boodigit==false) or ((numchiiar<48) or (numchiiar>57))) then
end--if
if (boonoban==false) then
while (true) do -- ordinary inner loop
varomongkosong = contabisbanned[numindeex+1] -- amount of elem unknown
if (type(varomongkosong)~="string") then
break -- abort inner loop (then fake outer loop) due to end of table
end--if
numukurran = string.len (varomongkosong)
if ((numukurran<2) or (numukurran>3)) then
break -- abort inner loop (then fake outer loop) due to faulty table
end--if
if (strqooq==varomongkosong) then
booisbadlk = true
break -- abort inner loop (then fake outer loop) due to violation
end--if
numindeex = numindeex + 1
end--while -- ordinary inner loop
end--if (boonoban==false) then
break -- finally to join mark
end--while -- fake loop -- join mark
return booisbadlk
end--function lfchkkodiv
------------------------------------------------------------------------
-- Local function LFCHKKODKN
-- Check whether the code is known
-- invoked module "mpiktbllki" with parameter "-" returns
-- bool string "0" or "1" (known)
-- Input : - strqoqoq
-- Output : - booisunknown
-- needs imported module "piktbllki"
local function lfchkkodkn (strqoqoq)
local varfrominvo = ""
local booisunknown = false
varfrominvo = piktbllki.ek { args = { strqoqoq , bin="1" } }
if (varfrominvo~="1") then
booisunknown = true
end--if
return booisunknown
end--function lfchkkodkn
------------------------------------------------------------------------
-- Local function LFBREW3KAT
-- Brew 3 categories from the bad code (generic and specific nome and specific loke)
-- Input : - strkatbase (kategory base name with namespace prefix)
-- - strspecnome (the bad lng code already sanitized)
-- - strspecloke (the caller name already sanitized)
-- - booxgene, booxnome, booxloke
-- Output : - strtigakucing (can be empty)
local function lfbrew3kat (strkatbase, strspecnome, strspecloke, booxgene, booxnome, booxloke)
local strtigakucing = ""
if (booxgene) then
strtigakucing = "[[" .. strkatbase .. "]]"
end--if
if (booxnome) then
strtigakucing = strtigakucing .. "[[" .. strkatbase .. " nome (" .. strspecnome .. ")]]"
end--if
if (booxloke) then
strtigakucing = strtigakucing .. "[[" .. strkatbase .. " loke (" .. strspecloke .. ")]]"
end--if
return strtigakucing
end--function lfbrew3kat
------------------------------------------------------------------------
---- MAIN EXPORTED FUNCTION ----
------------------------------------------------------------------------
function chklngcode.ek (arxframent)
-- general unknown type
local vartmp = 0 -- variable without type
-- special type "args" AKA "arx"
local arxourown = 0 -- metaized "args" from our own "frame"
local arxcaller = 0 -- metaized "args" from caller's "frame"
-- general "str"
local strkodo3 = "" -- code (obligatory)
local strkodo4 = "" -- code (optional)
local strpncalco = "" -- pagename core of the caller
local strret = "" -- output string
-- general "num"
local numbtkmo = 98 -- operation mode / type of result: "b" or "t" or "k"
local numallonk = 0 -- how "-" "??" should pass
local num012st3k = 2 -- tri-state sta "strkodo3"
local num012st4k = 2 -- tri-state sta "strkodo4" (remains 2 if only 1 code)
local num012stzz = 2 -- tri-state combo = min (num012st3k,num012st4k)
local numlong = 0 -- temp
local numchar = 0 -- temp
local numbull = 0 -- temp for peeking caller
local numposcol = 0 -- temp for peeking caller ONE-based position of colon
-- general "boo"
local boochktwo = false
local booallodg = false -- "true" to allow digit in middle position
local booskipbt = false -- "true" to skip test against ban table
local boonocat = false -- from "nocat=true"
local boodebug = false -- from "debug=true"
local boointer = false -- "true" on internal error (blocks categorization)
local boodoccek = false -- temp: do the check at all (maybe can be skipped)
local boonevagene = true -- @ for "constrfilter", default is "true"
local boonevanome = true -- @
local boonevaloke = true -- @
local boonekogene = true -- @
local boonekonome = true -- @
local boonekoloke = true -- @
---- GUARD AGAINST INTERNAL ERROR ----
-- "constrneva" and "constrneko" must be assigned and non-empty
if ((type(constrneva)~="string") or (type(constrneko)~="string")) then
boointer = true -- internal error -- was preassigned to "false"
else
if ((constrneva=="") or (constrneko=="")) then
boointer = true -- internal error -- was preassigned to "false"
end--if
end--if
---- SEIZE CALLER'S NAME (ONLY CORE NEEDED, NO PREFIX) ----
-- assigns "strpncalco" (pagename core) at least one char
-- a posible failure here is NOT fatal
vartmp = arxframent:getParent():getTitle()
numposcol = 0
strpncalco = ""
if (type(vartmp)=="string") then
strtmp = vartmp
numbull = string.len (strtmp)
if (numbull>2) then
vartmp = string.find (strtmp, ':', 1, true) -- plain text search
if (vartmp~=nil) then -- "not found" is NOT valid
numposcol = vartmp -- ONE-based position
if ((numposcol==1) or (numposcol==numbull)) then
numposcol = 0 -- invalid position of colon
end--if
end--if
end--if (numbull>2) then
end--if
if (numposcol~=0) then
strpncalco = string.sub (strtmp,(numposcol+1),numbull) -- remove prefix
end--if
---- GET THE ARX:ES ----
if (boointer==false) then
arxourown = arxframent.args -- "args" from our own "frame"
arxcaller = arxframent:getParent().args -- "args" from caller's "frame"
end--if
---- SEIZE 1 OR 2 ANONYMOUS PARAMETERS AND "XX=" SENT BY CALLER TO US ----
while (true) do -- fake loop
if (boointer) then
break -- to join mark
end--if
if (arxourown[3]) then
boointer = true -- internal error -- was preassigned to "false"
break -- to join mark -- 3 anon params are not appreciated
end--if
vartmp = arxourown[1] -- can be "nil"
if (type(vartmp)=="string") then
strkodo3 = vartmp -- give a f**k about risk of empty string
end--if
vartmp = arxourown[2] -- can be "nil"
if (type(vartmp)=="string") then
strkodo4 = vartmp -- give a f**k about risk of empty string
end--if
vartmp = arxourown["xx"] -- can be "nil" -- optional named
if (type(vartmp)=="string") then
numlong = string.len (vartmp)
if (numlong~=5) then
boointer = true -- internal error -- was preassigned to "false"
break -- to join mark -- need 5 digits
end--if
numchar = string.byte (vartmp,1,1) -- need "b" (default) or "t" "k"
if (numchar==116) then
numbtkmo = 116 -- requested "t" -- was preassigned to 98 ie "b"
else
if (numchar==107) then
numbtkmo = 107 -- requested "k" -- was preassigned to 98 ie "b"
else
if (numchar~=98) then
boointer = true -- internal error -- was preassigned to "false"
break -- to join mark
end--if
end--if
end--if (numchar==116) else
numchar = string.byte (vartmp,2,2) -- bool
if (numchar==49) then
boochktwo = true -- was preassigned to "false" -- check 2 codes
else
if (numchar~=48) then
boointer = true -- internal error -- was preassigned to "false"
break -- to join mark
end--if
end--if (numchar==49) else
numchar = string.byte (vartmp,3,3) -- four-state digit "0" ... "3"
if ((numchar<48) or (numchar>51)) then
boointer = true -- internal error -- was preassigned to "false"
break -- to join mark
end--if
numallonk = numchar - 48 -- allow "-" or "??"
numchar = string.byte (vartmp,4,4) -- bool
if (numchar==49) then
booallodg = true -- was preassigned to "false" -- allow digit
else
if (numchar~=48) then
boointer = true -- internal error -- was preassigned to "false"
break -- to join mark
end--if
end--if (numchar==49) else
numchar = string.byte (vartmp,5,5) -- bool
if (numchar==49) then
booskipbt = true -- was preassigned to "false" -- skip the extra ban test
else
if (numchar~=48) then
boointer = true -- internal error -- was preassigned to "false"
break -- to join mark
end--if
end--if (numchar==49) else
end--if (type(vartmp)=="string") then
break -- finally to join mark
end--while -- fake loop -- join mark
---- SEIZE 2 OPTIONAL NAMED PARAMETERS SENT BY SOMEONE TO US OR CALLER ----
-- "debug" overrides "nocat"
if (boointer==false) then
vartmp = arxourown["debug"] -- can be "nil"
if (type(vartmp)=="string") then
if (vartmp=="true") then
boodebug = true
end--if
end--if
end--if
if (boointer==false) then
vartmp = arxcaller["debug"] -- can be "nil"
if (type(vartmp)=="string") then
if (vartmp=="true") then
boodebug = true
end--if
end--if
end--if
if ((boointer==false) and (boodebug==false)) then
vartmp = arxourown["nocat"] -- can be "nil"
if (type(vartmp)=="string") then
if (vartmp=="true") then
boonocat = true
end--if
end--if
end--if
if ((boointer==false) and (boodebug==false)) then
vartmp = arxcaller["nocat"] -- can be "nil"
if (type(vartmp)=="string") then
if (vartmp=="true") then
boonocat = true
end--if
end--if
end--if
---- CARRY OUT THE HARD WORK -- TEST FOR OBVIOUS INVALIDITY ----
-- this hard work is NOT needed if:
-- # we already have an internal error
-- or
-- # result mode is "k" category and we have "nocat=true"
boodoccek = true
if (boointer) then
boodoccek = false
end--if
if ((numbtkmo==107) and boonocat) then -- "k" and "nocat=true"
boodoccek = false
end--if
if (boodoccek) then
if (lfchkkodiv(strkodo3,numallonk,booallodg,booskipbt)) then
num012st3k = 0
end--if
end--if
if (boodoccek and boochktwo) then
if (lfchkkodiv(strkodo4,numallonk,booallodg,booskipbt)) then
num012st4k = 0
end--if
end--if
---- CHECK WHETHER THE CODES ARE KNOWN ----
-- this hard work is NOT needed if:
-- # we already have an internal error
-- or
-- # result mode is "b" binary (then we do not distinguish "1" from "2")
-- or
-- # result mode is "k" category and we have "nocat=true"
boodoccek = true
if (boointer) then
boodoccek = false
end--if
if (numbtkmo==98) then -- "b" bool / binary mode
boodoccek = false
end--if
if ((numbtkmo==107) and boonocat) then -- "k" and "nocat=true"
boodoccek = false
end--if
if ((num012st3k==2) and boodoccek) then
if (lfchkkodkn(strkodo3)) then
num012st3k = 1
end--if
end--if
if ((num012st4k==2) and boodoccek and boochktwo) then
if (lfchkkodkn(strkodo4)) then
num012st4k = 1
end--if
end--if
---- BREW MIN ----
-- we have 2 separate tristate results "num012st3k" and "num012st4k"
-- "num012st4k" was preassigned to 2 and remains 2 all the time if
-- only one code is tested
-- an internal error ie "boointer" = "true" results in "num012stzz"
-- assigned to ZERO
-- combo result num012stzz = min (num012st3k,num012st4k)
if (boointer) then
num012stzz = 0 -- jaevlar
else
num012stzz = mathmin (num012st3k, num012st4k)
end--if
---- ASSIGN "STRRET" TO BOOL OR TRISTATE ----
-- possible modes in "numbtkmo" are 98 "b" (default) or 116 "t" or 107 "k"
if (numbtkmo==116) then -- "t" tristate
strret = string.char(num012stzz+48) -- this was rocket science
end--if
if (numbtkmo==98) then -- "b" bool
strret = "1" -- preassign output string to report "tolerable" (1 or 2)
if (num012stzz==0) then
strret = "0" -- change output string to report "evil" (0)
end--if
end--if
---- BREW CATEGORIES ----
-- here we process the "k" mode
-- we use the 2 separate tristate results "num012st3k" and "num012st4k"
-- 0 invalid -- 1 unknown -- 2 known
-- the strings are "constrneva" and "constrneko" and include the category
-- prefix and the name, but not "[[","]]" nor space before details
-- ("nome", "loke", "(", ")")
-- for obviously invalid codes we use "constrneva" and
-- include the bad string (sanitized)
-- for unknown codes we use "constrneko" and include the bad string
-- categorization can be blocked by several conditions:
-- # totally by "num012stzz" = 2 (code is or both codes are
-- known, no need to whine)
-- # totally by "nocat=true"
-- # totally by "boointer=true" (junk categories on
-- internal error are NOT appreciated)
-- # selectively by "num012st.." = 2 (code is known, no need to whine)
-- # selectively by ZERO:s in "constrfilter", length must be
-- 6 char:s, default for those 6 bool values is true
-- "strret" was preassigned to empty "" and is so
-- far untouched in the "k" mode
if ((num012stzz~=2) and (numbtkmo==107) and (boointer==false) and (boonocat==false)) then
if (string.len(constrfilter)==6) then
if (string.byte(constrfilter,1,1)==48) then
boonevagene = false
end--if
if (string.byte(constrfilter,2,2)==48) then
boonevanome = false
end--if
if (string.byte(constrfilter,3,3)==48) then
boonevaloke = false
end--if
if (string.byte(constrfilter,4,4)==48) then
boonekogene = false
end--if
if (string.byte(constrfilter,5,5)==48) then
boonekonome = false
end--if
if (string.byte(constrfilter,6,6)==48) then
boonekoloke = false
end--if
end--if
strkodo3 = lffixunsafe (strkodo3) -- sani lngcode (redu for num012st3k==1)
strpncalco = lffixunsafe (strpncalco) -- sanitize caller
if (num012st3k==0) then -- 2 possib in 1 of "num012st3k" & "num012st4k"
strret = strret .. lfbrew3kat (constrneva, strkodo3, strpncalco, boonevagene, boonevanome, boonevaloke)
end--if
if (num012st3k==1) then
strret = strret .. lfbrew3kat (constrneko, strkodo3, strpncalco, boonekogene, boonekonome, boonekoloke)
end--if
if (boochktwo) then
strkodo4 = lffixunsafe (strkodo4) -- sani lngcode (redu for num012st4k==1)
if (num012st4k==0) then -- 2 possib in 1 of "num012st3k" & "num012st4k"
strret = strret .. lfbrew3kat (constrneva, strkodo4, strpncalco, boonevagene, boonevanome, boonevaloke)
end--if
if (num012st4k==1) then
strret = strret .. lfbrew3kat (constrneko, strkodo4, strpncalco, boonekogene, boonekonome, boonekoloke)
end--if
end--if
if (boodebug) then
strret = lfdecencode (strret)
end--if
end--if ((num012stzz~=2) ... (boonocat==false)) then
---- RETURN THE JUNK STRING ----
return strret -- can vary depending on result type, even be empty
end--function
---- RETURN THE JUNK LUA TABLE ----
return chklngcode