Power Script Language (PSL) is a special feature of PowerTerm Pro which provides commands for creating scripts. These scripts can be used to automate tasks. For example, you can create a script to login to PowerTerm Pro automatically. PSL is intended for users with programming skills.

A command consists of one or more fields separated by spaces or tabs. The first field is the name of a command, which may be either a built-in command or a procedure consisting of a sequence of PSL commands. New-line characters are used as command separators, and semicolons may be used to separate commands on the same line. Each PSL command returns either a string result, or an empty string.

PSL has four additional syntactic constructs:

Curly braces {}

Square brackets []

Dollar sign $

Backslash \

PSL commands must be entered in lower case.

Curly Braces

Curly braces are used to group complex arguments. They allow you to nest one argument inside another. If the first character of an argument is an open brace, then the argument is not terminated by white space. Instead, it is terminated by the matching close brace. The argument passed to the command consists of everything between the braces, with the enclosing braces stripped off.

For example:

host = {vms unix {aix hp sun} aos}

The variable host will receive one argument:

"vms unix {aix hp sun} aos".

This particular command will set the variable host to the specified string.

If an argument is enclosed in braces, then none of the other substitutions described below is made on the argument. One of the most common uses of braces is to specify a PSL sub-program as an argument to a PSL command.

Square Brackets

Square brackets are used to invoke command substitution. If an open bracket appears in an argument, then everything from the open bracket up to the matching close bracket is treated as a command and executed recursively by PSL. The result of the command is then substituted into the argument in place of the bracketed string.

For example, the format command:

msg = [format {Data is %s bytes long} 99]

invokes print-like formatting (from the C language) and returns the string "Data is 99 bytes long", which is then assigned to the variable msg.

Dollar Sign

The dollar sign is used for variable substitution. If the dollar sign appears in an argument, then the following characters are treated as a variable name; and the contents of the variable are substituted into the argument in place of the dollar sign and name.

For example:

num = 99

msg = [format {Data is %s bytes long} $num]

The result is the same as the single command in the previous example.

The following are examples of common functions for the dollar sign in Power Script Language:

$P1

represents the variable of the parameter if P1 is the parameter.

$PC

counts the number of parameters in the command line.

Backslash

The backslash character may be used to insert special characters into arguments, such as curly braces or nonprinting characters.

Such special characters include the following:

[ ] { } $ t b r m

\xFF will send the hex code FF (where F can be any hex character: 0-9, A-F).

PSL uses only one type of data: strings. All commands, arguments to commands, results returned by commands and variable values are ASCII strings.

Although everything in PSL is a string, many commands expect their string arguments to have particular formats. There are three particularly common formats for strings:

Lists

Expressions

Commands

A list is just a string containing one or more fields separated by white space, similar to a command. Curly braces may be used to enclose complex list elements. These complex list elements are often lists in their own right.

For example:

{vms unix {aix hp sun} aos}

This is a list with four elements, the third of which is a list with three elements.

PSL provides commands for a number of list-manipulation operations, such as creating lists, extracting elements and computing list lengths.

The second common form for a string is a numeric expression. PSL expressions have the same operators and rules of precedence as expressions in the C language.

The expr PSL command evaluates a string as an expression and returns the result (as a string, of course).

For example:

expr {($x < $y) || ($z != 0)}

elicits ''1'' if the numeric value of variable x is less than that of variable y, or if variable z is not zero; otherwise it returns "0''. Several other commands, such as if and for, expect one or more of their arguments to be expressions.

The third common interpretation of strings is as commands (or sequences of commands). Arguments of this form are used in PSL commands that implement control structures.

For example:

if {$x < $y} {

swap = $x

x = $y

y = $swap

}

The if command receives two arguments here, each of which is delimited by curly braces. If is a built-in command that evaluates its first argument as an expression; if the result is non-zero, it executes its second argument as a PSL command. This particular command swaps the values of the variables x and y if x is less than y.

PSL also allows users to define command procedures written in the PSL language. The proc built-in command is used to create a PSL procedures (PSLproc).

For example:

proc factorial x {

if {$x == 1} {return 1}

return [expr {$x * [factorial [expr $x - 1]]}]

}

This PSL command defines a recursive factorial procedure. The proc command takes three arguments: a name for the new PSLproc, a list of variable names (in this case the list has only a single element, x), and a PSL command that comprises the body of the PSLproc. After this proc command has been executed, factorial may be invoked just like any other PSL command.

varName is located on the left side of the expression and the value you want to assign to the variable is located on the right.

For example:

B = 200

Two types of variables: Scalar and Array

A variable containing a single value is a scalar variable and the majority of the time fits ones needs. Other times, it is

convenient to assign more than one related value to a single variable. You then can create an array variable that can contain a series of values. Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses [ ] following the variable name.

A variable’s scope is determined by where it is declared. When you declare a variable within a procedure, only code within that procedure can access or modify the value of that variable. It has local scope and is called a local variable. Differently, a global variable declared outside a procedure, is recognizable to all the procedures in your script. An exception to the rule governing local variables is when the global command has been invoked to declare

PowerTerm Pro enables you to use the standard Microsoft DDE mechanism to communicate with other Windows applications. PowerTerm Pro can be a DDE client application or a DDE server application.

The DDE server application waits for requests from DDE clients, and allows them to supply or receive information.

For example:

A spreadsheet DDE server will let clients get data from cells and put data into cells of a file.

As a DDE server, PowerTerm Pro uses the server name PTW with topic PSL. Any application can request it to execute commands and return the related return data.

A client application can access PowerTerm Pro with the dde execute command or the dde request command plus an item that can consist of multiple valid PSL commands separated with ";".

The single DDE server PSL command is:

dde return value

After a dde request command is executed, the PowerTerm Pro DDE server sends the value from the last dde return command executed in this request. If no dde return command is executed, it returns an empty answer.

Examples for PowerTerm Pro as a DDE server might be:

Sending information to the host.

Reading information from the emulation screen.

As a DDE client, PowerTerm Pro performs one of several dde operations, depending on the option. The legal options are:

dde initiate applicationName topicName

Connects to the applicationName DDE server with topicName. Returns a conversation id for use with successive dde commands.

dde execute convId command

Executes a server command. Returns an empty string.

dde request convId item

Returns an item from the server.

dde poke convId item value

Changes an item of the server to the new value. Returns an empty string.

dde terminate convId

Terminates a DDE conversation with the server.

dde returns

Returns a value according to the option.

Examples

1 Assigns three numbers on the emulation screen to array

"cel"

for {i = 1} {$i < 4} {incr i} {

row = [expr $i + 3]

cel($i) = [screen-rect $row 10 $row 15]}

Initiates a DDE conversation with MicroSoft Excel file TEST.XLS.

conv

= [dde initiate EXCEL TEST.XLS]

Pokes the three numbers to three cels in TEST.XLS.

for {i = 1} {$i < 4} {incr i} {dde poke $conv R1C$i $cel($i)}

Requests the sum of those numbers from a result cel in TEST.XLS.

sum = [dde request $conv "R2C1"]

Terminates the DDE conversation.

dde terminate

$conv

Sends the result to the host application

.

send $sum

2 Initiates a DDE conversation with another PowerTerm Pro which is connected to another computer. Reads information from the screen (of the other host) and sends it to its own host.

conv = [dde initiate PTW PSL-B]

data = [dde request $conv {

dde return [screen 10 1 15 80]}]

ddeexecute $conv{send joe}

See PowerTerm Pro's online help for an explanation of each DDE command. To access the online help for DDE commands, select Contents from the Help menu and click the Index tab. Type dde and click Display.