OSF DCE Administration Guide--Core Components
Using the DCE Control Program Command Language
will be available for use inside and outside of your procedure, as shown.
You can use the return command to make your procedure return immediately. The
value of the argument to return becomes the procedure’s return value.
proc find {a} {
<some pattern matching script that looks for a specific CDS entry>
if {a != b} {
return 1
}
return 0
}
You can design procedures to take either no arguments or variable numbers of
arguments. For instance, a procedure with no arguments could simply perform some
straightforward operation as in the following example:
proc _do_create_group {} {
global rpcgroupname
rpcgroup create $rpcgroupname
}
You can also specify a default value for an argument by using a nested list structure in
the argument list. In the following example, the first argument, attr, must be supplied.
The second argument, value, defaults to 1 if no argument is supplied.
proc _attr_show {attr {value "unset"}} {
puts "$attr is $value"
}
Procedures can call other procedures. The current procedure can import variables from
any calling procedure by using the upvar command, as shown:
upvar level otherVar1 myVar1 otherVar2 myVar2
A level argument of 1 gets the variable context of the parent procedure. An argument of
2 gets the variable context of parent’s parent procedure. You can also specify levels
relative to the global context by preceding the level argument with #.Alevel of #0 gets
global variables. A level of #1 gets variables from a procedure invoked from the global
level.
The otherVar argument names the variable you want to import. You need to include the
myVar argument to rename the variable for use in the current procedure. The following
example renames the imported variable to cargs:
upvar 1 local_args cargs
Procedures can also execute scripts under the context of parent procedures by using the
uplevel command. This command offers a convenient way to manage your procedure’s
context. For instance, rather than import and manipulate numerous variables from a
parent procedure, use uplevel to connect to them all at once. The syntax is
124243 Tandem Computers Incorporated 2− 25