Juniper SYSTEM BASICS - CONFIGURATION GUIDE V 11.1.X Configuration Manual page 520

System basics configuration guide software for e series broadband services routers
Table of Contents

Advertisement

JUNOSe 11.1.x System Basics Configuration Guide
Additional parameters can be passed as well. Parameters can be local variables,
environmental variables, literals, or operations. The invoking macro passes local
variables by reference to the invoked macro. Passing parameters has no effect on
the invoking macro unless the parameter is a local variable that is changed by the
invoked macro. When the invoked macro completes execution, the local variable
assumes the new value for the invoking macro.
The invoked macro can use the param[ n ] expression to access parameters passed
to it, where n is the number of the parameter passed. This is useful if optional
parameters can be passed to a macro or if the same iterative algorithm needs to
process the parameters.
Use the expression param[0] to return the total number of parameters passed to the
macro. Use the return keyword to halt execution of the invoked macro and resume
execution of the invoking macro. Use the exit keyword to halt execution of all macros.
The following sample macro demonstrates macro invocation:
Example 1
<#
<# //---------------------------------------- #>
<# name := env.getline("What is your first name? ") #>
! First, <#name#>, we will invoke the if_examples and
! the while_examples macros...
<# tmpl.if_examples; tmpl.while_examples #>
! Hey <#name#>, have you noticed that your name backwards is:
!<# eman:= ""; tmpl.reversestring(name, eman); eman; "\n"#>
<#
<# endtmpl #>
<# argumentlist #>
<# if param[0] = 0; return; endif #>
! argumentList() was called with the following arguments:
<# while ++i <= param[0]#>
! <#param[i];"\n"#>
<# endwhile #>
<# endtmpl #>
<# reversestring (string, gnirts) #>
<# i := 0 + string; // i is now equal to the number of characters in string. #>
<# while --i >= 0; gnirts := gnirts $ substr(string, i, 1); endwhile #>
<# endtmpl #>
The following macro in file macro1.mac invokes a macro from within another file,
Example 2
macro2.mac:
<# callAnotherMacro #>
<# endtmpl #>
This macro passes the value of localVar to macroName2. The value of localVar remains
at 5 for callAnotherMacro, regardless of any operations upon that variable in the
second macro. In other words, an invoked macro in another file cannot return any
values to the invoking macro.
The output of callAnotherMacro looks like this:
490
Writing Macros
invoking_examples
tmpl.argumentlist("a", "b", "c")#>
<# localVar := 5 #>
macro macro2.mac macroName2 <# localVar #> string1
#>

Advertisement

Table of Contents
loading

This manual is also suitable for:

Junose 11.1

Table of Contents