global-functions: introduce $IfThenElse

This commit is contained in:
Christian Hesse 2020-07-16 20:34:27 +02:00
parent 5859b0406e
commit 910641b6fa

View file

@ -27,6 +27,7 @@
:global GetMacVendor; :global GetMacVendor;
:global GetRandomNumber; :global GetRandomNumber;
:global GetRandomSha256; :global GetRandomSha256;
:global IfThenElse;
:global IPCalc; :global IPCalc;
:global LogPrintExit; :global LogPrintExit;
:global MailServerIsUp; :global MailServerIsUp;
@ -339,6 +340,14 @@
:return $FingerPrint; :return $FingerPrint;
} }
# mimic conditional/ternary operator (condition ? consequent : alternative)
:set IfThenElse do={
:if ([ :tostr $1 ] = "true" || [ :tobool $1 ] = true) do={
:return $2;
}
:return $3;
}
# calculate and print netmask, network, min host, max host and broadcast # calculate and print netmask, network, min host, max host and broadcast
:set IPCalc do={ :set IPCalc do={
:local Input [ :tostr $1 ]; :local Input [ :tostr $1 ];