(menu.info)Section 8.3
8.3 Functions
=============
Anything matching '[a-zA-Z_]+' is taken as a function name, and an error
is generated if the function doesn't exist. The arguments of the
functions can be other functions, string constants or variables.
prefix()
returns the current prefix dir: either $rootprefix, or
$HOME/$userprefix, depending on who runs install-menu
ifroot($rootarg, $userarg)
if(getuid()==0) print $rootarg, else print $userarg
print($arg)
Same as just $arg; if $arg is empty, generate an error.
nstring($n, $string)
write $string $n times. So, nstring(3,"Aa") writes "AaAaAa".
(Useful in combination with level()).
esc($arg1,$arg2)
Print $arg1, but escape all occurrences of characters in $arg2 with
a '\' (thus, if arg1="hello", arg2="lo", print "he\l\l\o").
escwith($arg1, $arg2, $arg3)
Same as esc, but use $arg3 as escape sequence.
escfirst($arg1, $arg2, $arg3)
Same as escwith, but only escapes first occurrence of $arg2.
cppesc($arg1)
Escape anything that isn't a letter, number or _ with
$<hex-ascii-code>. So, for example, a '-' is replaced by '$2D'.
This way, $arg1 can be used as a #define in cpp.
tolower($arg)
toupper($arg)
Returns the argument set in lowercases resp uppercases.
replacewith($s, $replace, $with)
Search $s for occurrences of characters from string replace, and
replace them by the corresponding character in $with. Example:
replacewith("hello $world, %dir", "$% ", "123") returns:
"hello31world,32dir"
replace($s, $replace, $with)
Search $s for occurences of $replace and replace them with $with.
Note that the behaviour of this function is quite different than
the replacewith() function.
ifempty($arg1, $arg2)
If $arg1 is empty, print $arg2, otherwise print nothing. For
compatibility, $arg1="none" is interpreted as empty.
ifnempty($arg1, $arg2)
If $arg1 is not empty, print $arg2. For compatibility, the string
"none" is seen as empty.
ifelse($arg1,$arg2,$arg3)
If $arg1 is non-empty, print $arg2, otherwise $arg3. For
compatibility, the string "none" is seen as empty.
ifeq($arg1, $arg2, $arg3)
If ($arg1==$arg2) then print $arg3
ifneq($arg1, $arg2, $arg3)
If ($arg1!=$arg2) then print $arg3
ifeqelse($arg1, $arg2, $arg3, $arg4)
If ($arg1==$arg2) then print $arg3 else print $arg4
cond_surr($arg1, $arg2, $arg3)
If $arg1 is non-empty print $arg2$arg1$arg3, otherwise print
nothing. For compatibility, $arg1="none" is interpreted as empty.
iffile($arg1, $arg2)
If file $arg1 exists, and can be opened for reading by whoever
started the current process, return $arg2, otherwise return
nothing.
ifelsefile($arg1, $arg2, $arg3)
If file $arg1 exists, and can be opened for reading by whoever
started the current process, return $arg2, otherwise return $arg3.
catfile($arg1)
Return the contents of file $arg1.
shell($arg1)
Return the output of the shell command $arg1.
forall($array, "var", $exec)
For each element of the column separated array $array, set $var to
that element, and print $exec. Example:
!include lang.h
forall(sections_translations(), "lang", \
" section[" $lang "]=" translate($lang, title()) "\n")
parent($arg)
for $arg a "directory", return parent directory:
parent("/Debian/Applications/Editors") = "/Debian/Applications".
basename($arg)
return the last part of the parent directory:
basename("/Debian/Applications/Editors") = "Applications".
stripdir($arg)
everything after the last slash, i.e. what basename() should have
returned: stripdir("/Debian/Applications/Editors") = "Editors".
entrycount()
the number of entries in this menu.
entryindex()
returns relative position of this entry. Start with 0, last entry
is entrycount() - 1. BUG: if sort= anything other than $title,
then this entryindex() will return incorrect values.
firstentry($arg)
return $arg if this is the first entry of this menu (that is,
entryindex() = 0). Else, return nothing.
lastentry()
return $arg if this is the last entry in this menu (that is,
entryindex() = entrycount() -1). Else, return nothing.
level()
return nesting of this menu in the total menu tree.
add($arg1,$arg2)
sub($arg1,$arg2)
mult($arg1,$arg2)
div($arg1,$arg2)
returns the sum, difference, product or quotient of $arg1 and
$arg2. Note that the arguments are strings, that are converted to
integers. example: mult("24", entryindex())
rcfile()
examplercfile()
mainmenutitle()
rootsection()
rootprefix()
userprefix()
treewalk()
postoutput()
preoutput()
These functions all output whatever they were defined to be in the
menu-method file.
translate($lang, $text)
Translate $text into $lang using gettext, see 'forall' for an
example. Note that currently outputlanguage must be set to "C". If
$lang is the empty string, $text will be translated in the current
locale language. See sections_translations() for a list of
available translations.
implicit concatenation
String constants, variables and functions can be concatenated by
placing them after each other with a space in between, like:
"hello" ifelse($comma, $comma, " sorry" $period " comma not
defined") " world"
automatically generated by info2www version 1.2.2.9