Module:Sarang/Parlist

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Sandbox for testing purposes

Code

--Experimental module for some functions

-- now "Module:Parmlist":
--	gets one parameter in the structure aaa/bbb/ccc (also with html-reserved characters!)
--  returns [to the template] the parameters in the structure aaa|bbb|ccc

-- now "Module:Color2dec":
--functions hexval, hexdec

--end


require('strict')

local p = {}


function p.gsubst ( frame )			-- replace all "/" by "|"
 	local par = frame.args;
	if	par[1] == '' then
		par = mw.getCurrentFrame():getParent().args;
	end
    local strg = par[1] or ' ';
	local patt = par[2] or '/';		--	or '%/' 
    local repl = par[3] or '|';		--	?
    local cunt = par[4] or '';		--	?
    if par[trim]  =='1' then
    	strg = mw.text.trim( strg );
    	patt = mw.text.trim( patt );
    	repl = mw.text.trim( repl );
    end
    if par[trim1] =='1' then	strg = mw.text.trim( strg );	end
    if par[trim2] =='1' then	patt = mw.text.trim( patt );	end
    if par[trim3] =='1' then	repl = mw.text.trim( repl );	end
--	if patt == '/+/' then patt = '|%+|' end;
	return mw.ustring.gsub( strg, patt, repl, cunt ),_
end


--  Table for templates:  Legend; Legend-line, Legend2, Legend-small ...  (param pairs)
function p.legendt (frame)
	local frmp = frame.args
	local temp = frmp.t or frmp [1] or "Legend"
	local parm = frmp [2] or ""
	local wide = frmp [3] or ""
	local ppar = mw.getCurrentFrame(): getParent().args;
	local otab = {};
	local lg = ppar.lang or "";
	local v1 = ""
	for _, v in ipairs(ppar) do
		if v1 == "" then   
			v1 =  v;
		else
			table.insert(otab, frame:expandTemplate{ title = temp, args = { v1, v, lang = lg, p = parm, w = wide } });
			v1 = "";
		end	
	end
	if v1 ~= "" then		--	the problem when not a last pair
		table.insert(otab, frame:expandTemplate{ title = temp, args = { v1, "", lang = lg, p = parm, w = wide } });	-- last elem
	end
	return  table.concat (otab)
end --  function legendt

-- for numeric check
function p.numchk ( frame )
--	local lprm = frame     --  local parms
	local gprm = frame.args-- global parms
--	local pprm = mw.getCurrentFrame(): getParent().args;
	local inpt = {};
	local sndt = {};
	local dect = {0, 0, 0};
	local tmp = "";	-- temp. work string
	local err = "";	-- detected error 
	local fna = "";	-- assumed mode
	local fnc = "";	-- conversion mode
	local fno = "";	-- output mode
	local fnr = "";	-- "r" rgb(, "#" 
	local num = "";	-- number bytes
	local hex = "";	-- number + hex bytes
	local nhs = "";	-- number + hex bytes + separator slashes
	local rgp = "";	-- empty, or 3 rgb % signs
	local pts = 0;	-- numbers of decimal points	
	local sp1 = ",";	-- or "%,"
	local sp3 = ")";	-- or "%)"
	for i = 1, 3 do
		if gprm[i] == nil then gprm[i] = "" end
		inpt[i+3] = mw.text.trim( gprm[i] )
		inpt[i] = mw.ustring.upper( inpt[i+3] )
	end

	if inpt[3] ~= "" then fna = "4" -- three parms: 4a (or 3c)
	else
		if inpt[2] ~= "" then	-- 		only one param
			if		inpt[5] == "n" then fna = "n" -- 1: d2h
			elseif	inpt[5] == "h" then fna = "h" -- 2: h2d
			elseif	inpt[5] == "o" then fno = "o" -- 3: rgb (3ab or 4bcd)
			elseif	inpt[5] == "no" or inpt[5] == "on" then
				fna = "n" -- 1: d2h, or 4bcd
				fno = "o" -- editet
			elseif	inpt[5] == "ho" or inpt[5] == "oh" then
				fna = "h" -- 2: h2d, or 3ab
				fno = "o" -- editet
			elseif	inpt[5] == "%" then
				fna = "h" -- rgb (3ab) 
--				fno = "%" -- editet
				sp1 =  "%,"; sp3 = "%)";
			else	err = err.."4"	-- parm2 is wrong function code
			end
		elseif inpt[1] ~= "" then
			if	mw.ustring.sub( inpt[4], 1, 4) == "rgb(" then
				fna = "n"	-- 4cd
				fnr = "r"	-- rgb
				inpt[1] = mw.ustring.sub( inpt[1], 4, #inpt[1]-1)
			end
		end
	end

	if inpt[3] ~= "" then	-- 4a, 3c
		inpt[1] = inpt[1]  .."/".. inpt[2]  .."/".. inpt[3]
	end


	for i = 1, #inpt[1] do
		tmp = mw.ustring.sub( inpt[1], i, i)
--		if tmp >= "0" and tmp <= "9"	then
		if tmp == "0" or tmp == "1" or tmp == "2" or tmp == "3" or tmp == "4"
		or tmp == "5" or tmp == "6" or tmp == "7" or tmp == "8" or tmp == "9"	then
			num = num .. tmp
			hex = hex .. tmp
			nhs = nhs .. tmp
		elseif tmp == "." then	-- fnc = 4d
			if pts == 0 then
				num = num .. "."
				hex = hex .. "."
				nhs = nhs .. "."
				pts = 1
			else err = err.."5"		--	more than one point
			end
--		elseif tmp >= "A" and tmp <= "F"	then
		elseif tmp == "A" or tmp == "B" or tmp == "C" or tmp == "D" or tmp == "E" or tmp == "F" then
			hex = hex .. tmp
			nhs = nhs .. tmp
		elseif tmp == " " or tmp == "," or tmp == "-" or tmp == "/" then
			if  mw.ustring.sub( nhs, #nhs, #nhs ) ~= "/" then
				nhs = nhs .. "/"
				pts = 0				--	reset for next item
			elseif	mw.ustring.sub( inpt[1], i-1, i) ~= ", " then
--			else					--	if tmp ~= " " then
				err = err.."3"		--	more than one delimiter in sequ.	
			end
		elseif tmp == "%" then		-- fnc = 4d
			
			if  i < #inpt[1]	then inpt[7] = mw.ustring.sub( inpt[1], i+1, i+1)	end
			if	inpt[7] == ","	or	inpt[7] == ")"	then inpt[7] = "/"	end
			if  i < #inpt[1]	and	inpt[7] ~= "/"  then
				nhs = nhs .. "/"
				pts = 0				--	reset for next item
			end
			rgp = rgp .. "%"		--	3 times
			if #rgp > 3 then
				err = err.."6"		--	% sign error
			end
		elseif i == 1 then
			if		tmp == "(" then fnr = 'r'	-- fna = "n"
			elseif	tmp == "#" then fnr = '#'; fna = "h"	-- 3a edt rgb	
			else err = err.."2"		--	'(' or '#' not first char
			end
		elseif i == #inpt[1] then
			if	tmp == ")" and  fnr == 'r' then
				tmp = tmp	end		--	ignore end-')' when 'r'
		elseif tmp	~= "'"	then	--	ignore spacing separator
			err = err.."1"			--	character not identifyable
		end -- if
	end -- do


	if fnr == '#' and err == ""	then 
		if #hex == 3 then		--	3a
			inpt[6] = mw.ustring.sub( hex, 3, 3)..mw.ustring.sub( hex, 3, 3)
			inpt[5] = mw.ustring.sub( hex, 2, 2)..mw.ustring.sub( hex, 2, 2)
			inpt[4] = mw.ustring.sub( hex, 1, 1)..mw.ustring.sub( hex, 1, 1)
		elseif #hex == 6 then
			inpt[6] = mw.ustring.sub( hex, 5, 6)		
			inpt[5] = mw.ustring.sub( hex, 3, 4)		
			inpt[4] = mw.ustring.sub( hex, 1, 2)		
		else err = err.."#"	end	-- neither 6 nor 3 
		for i = 1, 3 do	
			dect[i] = tonumber( inpt[i+3], 16)
			if sp3 == "%)" then
				dect[i] = math.floor( dect[i] / .00255 ) / 1000
			end
		end
		fnc = "3"			--	3 
	end

	if #num < #hex or fna == "h" then
		if #nhs == #hex+2 then	--	3bC
			sndt = mw.text.split( nhs, "/" )
			for i = 1, 3 do	
				dect[i] = tonumber( sndt[i], 16)
				if dect[i] > 255 then
					err = err.."8" 
				else	
					if sp3 == "%)" then
						dect[i] = math.floor( dect[i] / .00255 ) / 1000
					end
				end	
			end
			fnc = "3"			--	3 
		else
			if fnr ~= '#' then
				dect[1] = tonumber( hex, 16)
				fnc = "2"		--	2 
			end
		end
	else	-- #num == #hex (a numeric value, and not 'h')
		if #nhs == #hex then	
			fnc = "1"			--	1 
			inpt[1]	= mw.ustring.format ( "%X", num )
			
		else	-- #nhs == #hex+2 == #num+2 (3 num values) -- 4A,4b or 4c,4d 
			dect = mw.text.split( nhs, "/" )	-- 
			fnc  = "4"			--	4 
			for i = 1, 3 do
				if rgp == "" then
					if tonumber ( dect[i] ) > 255 then -- 4A,4b,4c
						err = err.."8"
					end
					inpt[i]	= mw.ustring.format ( "%X", dect[i] )
	
				else	--	rgp = "%%%"	--	4d
					if rgp ~= "%%%" then
						err = err.."7"	-- not three "%"
					end
					if tonumber ( dect[i] ) > 100 then -- 4d
						err = err.."9"
					end
					dect[i+3] = math.floor( 2.55 * dect[i] + .5 )
					inpt[i] = mw.ustring.format ( "%X", dect[i+3] )
				end	-- if
				if #inpt[i] == 1 then inpt[i] = "0"..inpt[i] end 
			end	-- for
		end	-- if #nhs
	end	-- if #num


--		now errors may be encountered: 
--			1:	character not numeric/hexa
--			2:	'(' or '#' occurs at not first position
--			3:	separator or separator combination
--			4:	parm2 input wrong function code
--			5:	decimal point error
--			6:	% sign error
--			7:	not three "%"
--			8:	not all decimal color codes are < 256
--			9:	more than 100%
--		'num' contains all numeric bytes
--		'hex' contains all numeric plus hexadecimal bytes
--		'nhs' contains all numeric  plus hexadecimal bytes plus inbetween slashes
--		'rgp' may contain three '%' from rgb notation
--		dect contains three dec values when 3 input fields 
--		
--	if fnc == "4" then 	
--	return "err="..err..", fn="..fna..fnc..fno..fnr..", "..inpt[1].."; "..num.."~"..hex.."~"..nhs.." "..tostring(dect[1]).."'"..tostring(dect[2]).."'"..tostring(dect[3]).." "..rgp.." "..inpt[1].."'"..inpt[2].."'"..inpt[3]	
--	else
--	return "err="..err..", fn="..fna..fnc..fno..fnr..", "..inpt[1].."; "..num.."~"..hex.."~"..nhs.." "..tostring(dect[1]).."'"..tostring(dect[2]).."'"..tostring(dect[3]).." "..rgp;	-- test		
--	end

	if err ~= "" then return "Error = "..err	 
	elseif 	fnc == "1" then return inpt[1].."<sub>h</sub>"
	elseif 	fnc == "2" then return tostring(dect[1]).."<sub>d</sub>"
	elseif 	fnc == "3" then return "("..dect[1]..sp1..dect[2]..sp1..dect[3]..sp3
	elseif 	fnc == "4" then return " #"..inpt[1]..inpt[2]..inpt[3]
	end 

end	-- function numchk

function p.count ( frame ) 
	local gprm = frame.args; -- global parms
	local strg = gprm[1] or ' ';
	local pttn = gprm[2] or ' ';
	local addp = #pttn - 1;
	local cunt = 0;
    for i = 1, #strg-addp do
    	if mw.ustring.sub( strg, i, i+addp) == pttn
    		then cunt = cunt + 1;
    	end
	end
	return cunt		-- number of occurrencies
end	-- function count

----

-- hex to decimal value (0 ... FFFFFFFFFFF)
function p.h2d ( frame )
	local gprm = frame.args-- global parms
	return tonumber ( gprm[1], 16 )
end --  function h2d
-- hex to decimal value (0 ...  17592186044415)
function p.d2h ( frame )
	local gprm = frame.args-- global parms
	return mw.ustring.format ( "%X", gprm[1] )
end --  function d2h

function p.pru ( frame )
	local gprm = frame.args-- global parms
	return math.floor( 2.55 * gprm[1] + .5 )
end --  function pru 
function p.prz ( frame )
	local gprm = frame.args-- global parms
	return math.floor( gprm[1] / .0255) / 100
end --  function prz
function p.pr2 ( frame )
	local gprm = frame.args-- global parms
	local erg = math.floor( gprm[1] / .00255 ) / 1000
	return erg.."%"
end --  function pr2


function p.isExten1( frame )
	local fmod = require( "Module:File" )
	local gprm = frame.args
	local parm = ""
	if  gprm ~= nil then
		parm = gprm[1] or "g"  -- global
 	else
        parm = frame   or "l"  -- local 
	end
	local objm = fmod.mime( mw.text.trim ( parm ) )
	if "unknown" == objm then
		return parm
	else 
		return objm
	end
end -- function isExten1

function p.isExten2( frame )
	local fmod = require( "Module:File" )
	local gprm = frame.args
	local parm = ""
	if  gprm ~= nil then
		parm = gprm[1] or "g"  -- global
 	else
        parm = frame   or "l"  -- local 
	end
	local objm = fmod.File( mw.text.trim ( parm ) )
	if "unknown" == objm.extension() then
		return objm.extension() .. ": " .. parm
	else 
		return objm.extension() .. " = " .. parm
	end
end -- function 

function p.isExtens( frame )
	local fmod = require( "Module:File" )
	local gprm = frame.args
	local parm = ""
	if  gprm ~= nil then
		parm = gprm[1] or "g"  -- global
 	else
        parm = frame   or "l"  -- local 
	end
	if "unknown" == fmod.extension(  parm  ) then
		return parm
	else 
		return fmod.extension(  parm )
	end
end -- function 


-- horizontal or vertical list    {{#invoke:Sarang/Parlist|hvlist|wi|we|wh|wm}}
function p.hvlist (frame) 
--  local lprm = frame     -- local parms
	local gprm = frame.args-- global parms
--	local pprm = mw.getCurrentFrame(): getParent().args;
	local dir  = gprm.dir or "H"
	local lnk  = gprm.l or gprm.lnk or gprm.link  or "T0"; -- template to be performed
	local pfx  = gprm.p or gprm.pfx or gprm.pref  or ""; -- 'list' item {{Comma}}
	local ctab = {}

	if dir == "V" and pfx == "" then
		pfx  = "<br><span style=color:#69F>✦ </span>";     -- 'list' item
	end
	local max  = 0
	for i, v in ipairs(gprm) do
		max  = i
	end

	for i, v in ipairs(gprm) do
		if v ~= ""  then 
			if dir == "H" then
				local px = "";
				if i == 1 then 
					px = "&#32;"
				elseif i == max then
					table.insert(ctab, frame:expandTemplate{ title = "Conj-and" });
				else
					table.insert(ctab, frame:expandTemplate{ title = "Comma" });
				end
			else				--	elseif dir == "V" then
				if i == 1 then 
					px = "&#32;"
				end
			end
			table.insert(ctab, frame:expandTemplate{ title = lnk,  args = {v} } );
		end
	end
 	return  table.concat (ctab)
end -- function 




-- invoke for:  Template:AutVec
function p.authvec (frame)
	local parm = frame.args -- global parms
		return samefile ( parm [1], 0, "", mw.title.getCurrentTitle().namespace, mw.title.getCurrentTitle().text )  --  
end -- function 



-- function to show parmnames - each valued parm becomes a pair (name, value)
function p.showname (frame) 
	local args = mw.getCurrentFrame(): getParent().args;
	local otab = {};
	local typx = '';
--	open: typx = "A"
	table.insert(otab, frame:expandTemplate{ title = "Showname/display", args = { '', '', type="A"} });
	for name, value in pairs( args ) do 
		if	name	~= '' 
		or	value	~= ''	then
			typx = "1";
	--		if tonumber(name) == mw.text.trim(name) then typx = "2"; end
			if tonumber(name) ~= nil and tostring(name) ~= "0" then	typx = "2"; end
			table.insert(otab, frame:expandTemplate{ title = "Showname/display", args = { name, value, type=typx } });
		end
	end
--	clos: typx = "Z" 
	table.insert(otab, frame:expandTemplate{ title = "Showname/display", args = { '', '', type="Z"} });
  	return  table.concat (otab)
end -- function 
 


-- global tst maxn
function p.number (frame) 
	local args = mw.getCurrentFrame(): getParent().args;
	local rtab = {}
	local numb = 1;
	for i, v in ipairs(args) do
		table.insert(rtab, args[i]);
		numb = i
	end
	if  numb % 2 ==  1 then
 		table.insert( rtab, "" );
	end
-- 	return table.maxn(rtab), rtab[1], rtab[2], rtab[3], rtab[4], numb; 
	return mw.getCurrentFrame():expandTemplate{ title = 'Showname', args = rtab };
end -- function 

-- global tst maxn
function p.number0 (frame) 
	local args = mw.getCurrentFrame(): getParent().args;
	local rtab = {}
	local numb = 1;
	for i, v in ipairs(args) do
		table.insert(rtab, args[i]);
		numb = i
	end
	if  numb % 2 ==  1 then
 		table.concat( args, "even" );
	end
--	return table.maxn(args).." = "..args [table.maxn(args)]; 
  	return table.maxn(rtab), args[1], args[2], args[3], args[4], numb; 
--	return mw.getCurrentFrame():expandTemplate{ title = 'Showname/display', args = args };
end -- function 
-- global tst maxn
function p.number1 (frame) 
	local args = mw.getCurrentFrame(): getParent().args;
	if  table.maxn( args ) % 2 ==  1 then
 		table.insert( args, "even" );
	end
--	return table.maxn(args).." = "..args [table.maxn(args)]; 
  	return table.maxn(args), args[1], args[2], args[3], args[4], 17%2 ; 
--	return mw.getCurrentFrame():expandTemplate{ title = 'Showname/display', args = args };
end -- function 
-- global tst maxn
function p.number2 (frame) 
--	local args = frame.args
	local args = mw.getCurrentFrame(): getParent().args;
	local rtab = {}
	rtab = args
	pnum =  table.maxn( rtab )
	if  table.maxn( rtab ) % 2 ==  1 then
 		table.insert( rtab, "even" );
	end
--	return table.maxn(rtab).." = "..rtab [table.maxn(rtab)]; 
  	return pnum .. "  " .. table.maxn(rtab); 
--	return mw.getCurrentFrame():expandTemplate{ title = 'Showname/display', args = rtab };
end -- function 
-- global tst maxn
function p.number3 (frame) 
	local args = frame.args
--	local args = mw.getCurrentFrame(): getParent().args;
	local exis = ""
	for i, v in ipairs(args) do
		if v == "n"
--		or v == ("y" or "z")	-- das geht so nicht
		or v == "notself" then
			exis = i.."="..v;
		end
	end
  	return exis; 
end -- function 

-- global next output
function p.output (frame) 
	local args = frame.args
  	return mw.getCurrentFrame():expandTemplate{ title = 'Word-lang', args = args };
end -- function 




-- test parm "b1="
function p.parmtest (frame) 
--  local locp = frame
	local dirp = frame.args
  	if dirp[1]==nil then 
		dir="nil"
	elseif dirp[1] == "" then
		dir="emp"
	else
		dir=dirp[1]
	end

	dir  = "NsNr = " .. mw.title.getCurrentTitle().namespace .. "<br>" 
		.. "text = " .. mw.title.getCurrentTitle().text .. "<br>" 
		.. "pref = " .. mw.title.getCurrentTitle().prefixedText .. "<br>"
		.. "FULL = " .. mw.title.getCurrentTitle().fullText .. "<br>"
		.. "root = " .. mw.title.getCurrentTitle().rootText .. "<br>"
		.. "base = " .. mw.title.getCurrentTitle().baseText .. "<br>"

	local argp = mw.getCurrentFrame(): getParent().args;
  	if    argp == nil then 
 		return	dir .. "; no params"  -- missing
	elseif argp.b1  == nil then
		return	dir .. "; missg b1"   -- missing
	elseif argp.b1 == "" then
		return	dir .. "; empty b1"   -- empty
	else
		return	dir .. ": b1 = " ..  argp.b1  -- value
	end
end -- function  


-- function of Ud:PerfektesChaos, generates a 4096 elements table
function p.colortab ()
	local iR, iG, iB,  hR, hG, hB,  h, s, g
	local r    = ""
	for iR = 0, 15 do
		hR = string.format( "%X", iR )
		r = r .. "\n=== " .. hR .. "xx"
		r = r .. " ===\n<table width='100%' border='0' style='text-align:center'>"
		for iG = 0, 15 do
			hG = string.format( "%X", iG )
			r    = r .. "\n<tr>"
			for iB = 0, 15 do
				hB = string.format( "%X", iB )
				h = hR .. hG .. hB
				if iR * 3 + iG * 10 < 98 then
					s = "FFF"
				else
					s = "000"
 				end
				g = h
				if	mw.ustring.find("0369CF", hR) ~= nil and
					mw.ustring.find("0369CF", hG) ~= nil and
					mw.ustring.find("0369CF", hB) ~= nil then
					g = "'''" .. g .. "'''"
				end  
				r = r .. string.format( "\n<td title='#%s' style='background:#%s;color:#%s'>%s</td>",  h, h, s, g )
			end -- for iB
			r = r .. "\n</tr>"
		end -- for iG
		r = r .. "\n</table>"
	end -- for iR
	return r
end -- function colortab


-- for Template:ColorString (Igen/cbox   -   param pairs)
function p.colorbox (frame)
	local ppar = mw.getCurrentFrame(): getParent().args;
	local otab = {};
	local lg = ppar.lang or "{{PAGELANGUAGE}}";	 	--
	local tc = ppar.text or ppar.textcolor or "";	-- #F8F
	local v1 = "";
	local p2 = "";
	local x  =  0;
	for i, v in ipairs(ppar) do
		if i <= 2 then
			p2 = v;			-- param3: code ""/" ", B, C, D, M/-, L, S; T
		else
			x = i - 2;
			if v1 == "" then   
				v1 = mw.text.trim( v );
				t1 = ppar ["t" .. tostring( x )] or tc;
			else
				t2 = ppar ["t" .. tostring( x )] or tc;
				if p2 ~= "B" then t0 = ppar ["t" .. tostring( x/2 )] or tc; end
				table.insert(otab, frame:expandTemplate{ title = "Igen/cbox", args = { v1, v, p2, t1, t2, lang = lg, t0 } });
				v1 = "";
			end
		end
	end
	if v1 ~= "" then
		table.insert(otab, frame:expandTemplate{ title = "Igen/cbox", args = { v1, "", p2, tc, lang = lg } });	-- last elem		
	end
	return  table.concat (otab)
end --  function colorbox

-- ==============================

-- Template:Tle  
function p.tleparm (frame) 
--  local lprm = frame     -- local parms
--	local gprm = frame.args-- global parms
	local pprm = mw.getCurrentFrame(): getParent().args;
	local par1 = "";
	local par3 = pprm.f      or ""; -- form feed
	local par4 = pprm.style  or ""; -- style for value
	local par5 = pprm.style2 or ""; -- style for param
	local ctab = {}

	for i, v in ipairs(pprm) do
		par1 = pprm ["p" .. tostring( i )] or "";
		if par1 == "" and mw.text.trim(pprm.number) ~= "" then 
			par1 = tostring( i )
		end
		if mw.text.trim(v) == "" then v = "&thinsp;" end
		table.insert( ctab, frame:expandTemplate{ title = "Tle/parm",  args = {  par1, v, par3, par4, par5} } );
	end
 	return  table.concat (ctab)
end -- function 

--
function p.file ( frame )
	local args = frame.args
	local fnam = args[2] or ""
	local ind = string.lower(string.gsub(fnam,"^.*%.([^%.]*)$","%1"))
	local map = {svg=1, png=1, jpg=1, jpeg=1, gif=1, tif=1, tiff=1, xcf=1, mid=1, pdf=1}
	if map[ind] then
		return  fnam .. "-yes"
	else
		return  fnam .. "-not galleryable"
	end
end -- function 



-- global init for Image generation
function p.igen ( frame )
	local args = frame.args
	local argstr = mw.text.trim( args[1] ) or 'xx/yy/zz'; 
	local tmplte = mw.text.trim( args[2] or 'Igen/cbx' );
	local argt   = mw.text.split( argstr, "/" );
	return mw.getCurrentFrame(): expandTemplate { title = tmplte, args = argt };
end -- function 

-- global init tsplit
function p.tsplit ( frame )
	local lpar = frame.args
	local argstr = mw.text.trim( lpar[1] ) or 'xx/yy/zz'; 
	local argt  =  mw.text.split( argstr, "/" );
	return argt[1] .. '!' .. argt[2] ..argt[3] ..argt[4] ..argt[5].. ' from ' .. lpar[1];
end -- function tsplit

-- function textsplit (for parameter names, with equal signs)
function p.q_split ( frame )
	local lpar   = frame.args
	local parstr = mw.text.trim( lpar[1] ) or ' '; 
	local tmplte = mw.text.trim( lpar[2] ) or 'Igen';  -- 
	local outtab = {};
	local parind = 0;
	local argtab = mw.text.split( parstr, "/" );	-- becomes "|"
	local fpos   = nil;
	
	for i, v in ipairs(argtab) do
	--	if v ~= '' then
			v	= mw.ustring.gsub( v, "¦" , "/" );	-- repl brokenbar by slash ,_
			fpos = mw.ustring.find( v, '~' );		-- "~" becomes "="
			if fpos == nil then
				if v ~= '+' then			
					parind = parind + 1;
					outtab [ parind ] =  v;				-- positional
				end
			else
				if '+' ~=  mw.ustring.sub ( v, fpos+1 ) then			
					outtab [ mw.ustring.sub ( v, 1, fpos-1 ) ] =  mw.ustring.sub ( v, fpos+1 );
				end
			end
	--	end
	end	
--	if 	mw.ustring.sub (tmplte,1,4) == 'Igen'  then
		fpos = mw.ustring.find( outtab [1], ':' );	--	shortcut:
		if fpos ~= nil then		-- "T;xx:yy" > "T", "s=xx", "w=yy"
			outtab['w'] = mw.ustring.sub ( outtab [1], fpos+1 );
			outtab[1] = mw.ustring.sub ( outtab [1],1, fpos-1 );
		end
		fpos = mw.ustring.find( outtab [1], ';' );	-- shortcut:
		if fpos ~= nil then							-- "T;d" > "T", "s=d"
			outtab['s'] = mw.ustring.sub ( outtab [1], fpos+1 );
			outtab[1] = mw.ustring.sub ( outtab [1],1, fpos-1 );
		end
	--	if	mw.ustring.sub (tmplte,5) ~= '/coa' then
		if	mw.ustring.sub (tmplte,5) ~= 'name' then
			table.insert( outtab, '+' );				--	re_insert the "+"
		end
--	end
	return mw.getCurrentFrame(): expandTemplate { title = tmplte, args = outtab };
end -- function q_split

-- local=frame/global=args[1]
function p.inptest ( frame )
	local args = frame.args
	if  args then
        return  'g_args1: ' .. args[1] 
	elseif  frame then
        return  'l_frame: ' .. frame
	end
end -- function inptest
--
function p.inpcall ( frame )
	local args = frame.args
	local parm = p.inptest ( args[1] );
	return  parm
end -- function 

--
function p.testinp ( frame_args, arg_list )
	local  testfunc = require ( "Module:String" )
	local  testparm = testfunc._getParameters ( frame_args, arg_list )
	return testparm; 
end -- function   


-- "File:DEK Deutsche Einheitskurzschrift - Verkehrsschrift - ?????.svg"
function p.dek_name ( frame )
	local args = frame.args;
	return mw.ustring.sub ( args[1], 53, #args[1]-4 );  
end -- function 


function p.igentopx ( frame )
	local pprm = mw.getCurrentFrame(): getParent().args;
	local otab = {};
	local otx1 = "{{#ifeq:{{{lang|{{int:lang}}}}}|en|{{W|"
	local otx2 = "}}|{{Igen/top:"
	local otx3 = "|{{lc:{{{1}}}}}|lang={{{lang|{{int;lang}}}}}}"
	for _, v in ipairs(pprm) do
		local itab = mw.text.split ( v, "/" )
		otxt = otx1 .. mw.text.trim(itab[2]) .. otx2 ..  itab[1] .. otx3
		table.insert(otab, frame:expandTemplate{ title = "=", args = { otxt  } });
	end
 	return  table.concat (otab);
end -- function 

function p.igentop ( frame )
	local pprm = mw.getCurrentFrame(): getParent().args;
	local lprm = frame.args
 	return frame:expandTemplate{ title = "Igen/coa", args= { pprm.dif, sub=pprm.sub, top=pprm.top, lang=pprm.lng } };
end -- function 



function p.testlink(frame)
	local args = require('Module:Arguments').getArgs(frame)
	frame = mw.getCurrentFrame()
--	local link = args[link]
	if  args[2] == nil  then
        return  'link = NIL'
	elseif args[2] == '' then
        return  'link = Empty'
	else return  'link = ' .. args[2]
	end
end -- function  

---- 
-- for Template:userlist  (horizontal - but vertical when dir=I/O/U/V)
function p.userlist (frame)
--	local lpar = parm       --  local parms
	local gpar = frame.args -- global parms (par/P,dir/V)
	local ppar = mw.getCurrentFrame(): getParent().args;
	local ctab = {};
	local htab = {};
	local ltab = {};
	local ntab = {};
	local otab = {};
	local ptab = {};
	local ttab = {};
--@	local rtab = {};
--@	local qtab = {};
	local wtab = {};
	local Xtab = {};

	local cas  = ppar.c or ppar.case or "";
	local hil  = ppar.h or ppar.hilite or "";
	local lnk  = ppar.l or ppar.link or "";
	local nam  = ppar.n or ppar.name or "";
	local opt  = ppar.o or ppar.opt  or ppar.option or "";
	local pag  = ppar.p or ppar.page or "";
--@	local pr4  = ppar.q or ppar.qpar or ppar.par4 or "";
--@	local pr5  = ppar.r or ppar.rpar or ppar.par5 or "";
	local trl  = ppar.t or ppar.i18n or ppar.translate or "";
	local wik  = ppar.w or ppar.wiki or ppar.lang or "";

	local max  = 0;
	local cor  = 0;
	local x    = 0;  -- running index, can be ~= i
	local y    = 0;  -- running index, can be ~= i
	local odd  = 0;
	local out  = 0;
	local plus = ""; -- opt

	local prim = ""
	local prfx = ":"
	local pend = ""
	if gpar.dir == "O" then		-- ordered list
		prim = "<ol>";
		prfx = "<li>";
		pend = "</ol>";
	end	
	if gpar.dir == "U" then		-- unordered list
		prim = "<ul>";
		prfx = "<li>";
		pend = "</ul>";
	end
	if gpar.dir == "V" then		-- vertical list
		prim = " ";
		prfx = "<br><span style=color:#69F>✦ </span>";
	end	

	for _, v in ipairs(ppar) do
		v = mw.text.trim ( v );
		if v == "+" then
			plus = "+";
		elseif  v == "-" then
			if plus == "" then plus = "-" end
		else
			y = y + 1;
			if gpar.par == "P"	-- pairs of (user, name)
			and y % 2 == 0 then	-- 1=user, 0=name
				x = x;		
			else
				x = x + 1;
				ctab [x] = ppar ["c" .. tostring( x )] or "-";
				htab [x] = ppar ["h" .. tostring( x )] or "-";
				ltab [x] = ppar ["l" .. tostring( x )] or "-";
				ntab [x] = ppar ["n" .. tostring( x )] or "-";
				otab [x] = ppar ["o" .. tostring( x )] or "/";
				ptab [x] = ppar ["p" .. tostring( x )] or "-";
--@				rtab [x] = ppar ["r" .. tostring( x )] or "-";
--@				qtab [x] = ppar ["q" .. tostring( x )] or "-";
				ttab [x] = ppar ["t" .. tostring( x )] or "-";
				wtab [x] = ppar ["w" .. tostring( x )] or "-";
			end
		end
		max  = x;
	end -- for
	odd  = y % 2; -- 1 when last one not paired

	if plus > "" and opt == "" then
		opt = plus;		-- discrepancy ? opt has priority
	end
	x   = 0;
	y   = 0;
	local vv = "";
	for _, v in ipairs(ppar) do
		v = mw.text.trim ( v );
		if v ~= "+" and v ~= "-" then
			y = y + 1;
			if gpar.par == "P"	-- pairs of (user, name)
			and y % 2 == 1 		-- 1=user, 0=name 
			and odd == 0 then	-- last one paired
				vv = v;	 		-- userid
			else
				x  =  x + 1;
				local cs = cas;  if ctab[x] ~= "-" then  cs = ctab[x] end
				local hl = hil;  if htab[x] ~= "-" then  hl = htab[x] end
				local lk = lnk;  if ltab[x] ~= "-" then  lk = ltab[x] end
				local nm = nam;  if ntab[x] ~= "-" then  nm = ntab[x] end
				local op = opt;  if otab[x] ~= "/" then  op = otab[x] end
				local pg = pag;  if ptab[x] ~= "-" then  pg = ptab[x] end
--@				local p4 = pr4;  if rtab[x] ~= "-" then  p4 = rtab[x] end
--@				local p5 = pr5;  if qtab[x] ~= "-" then  p5 = qtab[x] end
				local tr = trl;  if ttab[x] ~= "-" then  tr = ttab[x] end
				local wk = wik;  if wtab[x] ~= "-" then  wk = wtab[x] end

				if gpar.par == "P"	then	--	y%2 = 0 (name)
					if odd == 1	then	--	no: last user:
						vv = v;			--	user
					else
						nm = v;			--	name
					end
				else 
					vv = v;
				end
				if hl ~= "" then
					if nm == "" then nm = vv; end
					nm = "<" .. hl .. ">" .. nm .. "</" .. hl .. ">";
				end
				local p1 = "";  -- prefix
				local p2 = "";  -- postfix
				if pg == "t" or pg == "wt" or pg == "tw" then	p1 = "&#32;talk";	 end
				if pg == "w" or pg == "wt" or pg == "tw" then	p2 = "~commonswiki"; end
--					{{Uc}} --> [[Special:Contributions/userid]]

				if vv ~= "" and vv ~= "×" then
					if gpar.dir == "I" 
					or gpar.dir == "O" 
					or gpar.dir == "U" 
					or gpar.dir == "V" then  -- vertical list
						if out == 0 then
							table.insert(Xtab, frame:expandTemplate{ title = "=", args = { prim } });
						end
						table.insert(Xtab, frame:expandTemplate{ title = "=", args = { prfx } });
						out = out + 1;
					else						--	
						if x == 1 then
							x = 1		--	??? horizontal list initializing (text)
						elseif x == max then
							table.insert(Xtab, frame:expandTemplate{ title = "Conj-and" });
						else
							table.insert(Xtab, frame:expandTemplate{ title = "Comma" });
						end
					end

					if mw.ustring.sub( vv, 1, 1 ) == "{" then
						table.insert(Xtab, frame:expandTemplate{ title = "=", args = { vv } });
					else
					table.insert(Xtab, frame:expandTemplate{ title = "U/main", args = { vv, nm, wk, op, link=lk, par1=p1, par2=p2, case=cs, i18n=tr} });
					end
				end
			end
		end
	end -- for

	if	out > 0 and pend > " " then
		table.insert(Xtab, frame:expandTemplate{ title = "=", args = { pend } });
	end
	return  table.concat (Xtab);
end  --  function userlist


-------------------------------------------------------
-- helper function for:  ownbased, and filelist
local function samefile ( fnam, numb, frst ) 
	local name  = mw.text.trim( fnam ) or ""
	if mw.ustring.sub(name, 1, 1) == "."
		then
			local nsnr = tonumber( mw.title.getCurrentTitle().namespace );
			local page = mw.title.getCurrentTitle().text;
			local part = "Example"   --  default name
			if nsnr == 6 or nsnr == 7
			then local parts = mw.text.split(page , '.', true)
				 local upTo = #parts - 1    -- copied from Module:File
				 part = table.concat(parts, '.', 1, math.max(upTo, 1))
			end
			if     name == "."  then name = part .. ".png";
			elseif name == ".p" then name = part .. ".png";
			elseif name == ".j" then name = part .. ".jpg";
			elseif name == ".g" then name = part .. ".gif";
			elseif name == ".s" then name = part .. ".svg";
			elseif name == ".t" then name = part .. ".tif";
			elseif name == ".x" then name = part .. ".xcf";
			else					 name = part ..  name;
			end
	elseif  name ==  ""
		then
			local nsnr = tonumber( mw.title.getCurrentTitle().namespace );
			local page = mw.title.getCurrentTitle().text;
			if tonumber( numb ) == 1
					then name = "Example.svg";
					if nsnr == 6 or nsnr == 7
						then name = page;
					end
			else name = mw.text.trim( frst );
				if name == ""
				or mw.ustring.sub(name, 1, 1) == "."
					then name = "Example.svg";
					if nsnr == 6 or nsnr == 7
						then name = page;
					end
				end
			end
	end
	return name
end -- function samefile

---++++++++++++++++++++++++++++++++++++++++++++++++++++


-- horizontal file list for:  Template:Filelist;  Template:File 
--   vertical file list for:  Template:Other versions;  Template:Derived from,  Template:Derivative versions 
function p.filelist (frame) 
--  local lpar = frame     --  local parms
	local gpar = frame.args-- global parms
	local ppar = mw.getCurrentFrame(): getParent().args;
	local ctab = {};
	local ltab = {};
	local ntab = {};
	local dtab = {};
	local otab = {};
	local ptab = {};
	local qtab = {};
	local rtab = {};
	local vtab = {};
	local ktab = {};
	local itab = {};
	local xtab = {};
	local btab = {};
	local ttab = {};
	local mnum = 0; 
	local dir  = gpar[1] or "none"
	local nam  = ppar.n             or ppar.name    or ""; 
	local dis  = ppar.d or ppar.dis or ppar.display or ""; 
	local lnk  = ppar.l or ppar.lnk or ppar.link    or "";
	local opt  = ppar.o or ppar.opt or ppar.option  or "";
	local pre  = ppar.p or ppar.pre or ppar.pretext or "";
	local pr4  = ppar.par4 or ppar.qpar or "";
	local pr5  = ppar.par5 or ppar.rpar or "";
	local pr6  = ppar.par6 or ppar.vpar or "";
	local by0  = ppar.user or ppar.by or "";
	local wik  = ppar.w or ppar.k or ppar.wiki or ppar.sisterproject or "";
	local int  = ppar.i or ppar.int or ppar.ind or ppar.inter or "";
	local pfx  = ppar.x or ppar.pfx or ppar.prefix  or ""; -- 'list' item {{Comma}}
	if  mw.ustring.sub(dis, -2) == 'px' then 
		dis = mw.ustring.sub(dis, 1, mw.ustring.len(dis) -2)
	end
	if dir == "vert" and pfx == "" then
		pfx  = "\n* ";     -- 'list' item
	end

	for i, v in ipairs(ppar) do
		ntab [i] = ppar ["n" .. tostring( i )] or ppar ["l" .. tostring( i )] or "-";
		dtab [i] = ppar ["d" .. tostring( i )] or "-";
		ltab [i] = ppar ["l" .. tostring( i )] or "-";
		otab [i] = ppar ["o" .. tostring( i )] or "-";
		ptab [i] = ppar ["p" .. tostring( i )] or "-";
		qtab [i] = ppar ["q" .. tostring( i )] or "-";
		rtab [i] = ppar ["r" .. tostring( i )] or "-";
		vtab [i] = ppar ["v" .. tostring( i )] or "-";
		ktab [i] = ppar ["k" .. tostring( i )] or "-";
		itab [i] = ppar ["i" .. tostring( i )] or "-";
		xtab [i] = ppar ["x" .. tostring( i )] or "-";
		ttab [i] = ppar ["t" .. tostring( i )] or "-";
		btab [i] = ppar ["b" .. tostring( i )] or ppar ["by" .. tostring( i )] or "-";
		mnum  = i;
	end

	for i, v in ipairs(ppar) do
		local nm = nam;  if ntab[i] ~= "-" then  nm = ntab[i] end
		local ds = dis;  if dtab[i] ~= "-" then  ds = dtab[i] end
		local ln = lnk;  if ltab[i] ~= "-" then  ln = ltab[i] end
		local pr = pre;  if ptab[i] ~= "-" then  pr = ptab[i] end
		local op = opt;  if otab[i] ~= "-" then  op = otab[i] end
		local p4 = pr4;  if qtab[i] ~= "-" then  p4 = qtab[i] end
		local p5 = pr5;  if rtab[i] ~= "-" then  p5 = rtab[i] end
		local p6 = pr6;  if vtab[i] ~= "-" then  p6 = vtab[i] end
		local pk = wik;  if ktab[i] ~= "-" then  pk = ktab[i] end
		local pi = int;  if itab[i] ~= "-" then  pi = itab[i] end
		local px = pfx;  if xtab[i] ~= "-" then  px = xtab[i] end
		local tx = "";   if ttab[i] ~= "-" then  tx = ttab[i] end
		local by = by0;  if btab[i] ~= "-" then  by = btab[i] end
		local vv = v;

		vv = samefile ( vv, i,  ppar [1] )
			
		if vv ~= ""  then 
			if dir == "hori" then
				px = "";
				if i == 1 then 
					px = "&#32;"
				elseif i == mnum then
					table.insert(ctab, frame:expandTemplate{ title = "Conj-and" });
				else
					table.insert(ctab, frame:expandTemplate{ title = "Comma" });
				end
			else				--	elseif dir == "vert"ical then
				if i == 1 then 
					px = "&#32;"
				end
			end
			table.insert(ctab, px .. frame:expandTemplate{ title = "F", args = {vv, nm, ds, op, p4, p5, p6, l= pk, lang= pi, link= ln, p=pr, by= by} });
			if tx ~= ""  then
				table.insert(ctab, frame:expandTemplate{ title = "=", args = { tx } } );			
			end
		end
	end
 	return  table.concat (ctab)
end -- function filelist

function p.slashes( frame )
	local gprm = frame.args
	if  gprm[1] ~= "" and	not	gprm[2] and
		mw.ustring.find(gprm[1], "/", 1, true)  then
		return tostring(mw.ustring.find(gprm[1], "/", 1, true))
	else
		return "not."
	end		--  {{#invoke:Sarang/Parlist|slashes|aaa/bbb/ccc}}
end

--  rpslsh 
function p.repslsh (frame)
	local frmp = frame.args
	return "{{Location|" .. mw.ustring.gsub( frmp[1], "/" , "|" ) .. "}}";				-- replace slash by pipe 
end	-- function repslsh
 
function p.catsort (frame)
	local frmp = frame.args
	local strg = frmp [1] or " "
	strg = mw.ustring.gsub( strg, "/" , "|" );					-- replace slash by pipe 
	strg = mw.ustring.gsub( strg, "[\n]" , "]]\n[[Category:" );	-- replace lf by Cat
	return strg
end	-- function catsort

return p;