GNU Rush legacy configuration syntax (split by node):   Section:   Chapter:FastBack: Rule   Up: Transformations   FastForward: Include   Contents: Table of ContentsIndex: Concept Index

3.2.3 Transform

The transform action modifies the value of the command line, or any particular word of it, according to a sed-like s-expression. S-expressions are described in more detail below (see s-expression). This action has several forms.

Rule Config: transform expr

Apply expression expr to entire command line. For example, the action below adds a -t option after the command name:

transform s,^[^ ]+,& -t,
Rule Config: transform pattern expr

Expand pattern as described in patterns, apply expr to the expansion, and replace the command line with the result.

Rule Config: transform[n] expr

Apply expression expr to nth word from the command line. Notice, that square brackets are part of the statement syntax. See indexing, for a detailed description of n and its syntax.

Rule Config: transform[n] pattern expr

Apply expression expr to the expanded pattern and assign the result to nth word. See patterns, for a description of patterns and their expansion. See indexing, for a detailed description of n and its syntax.

The example below replaces the 0th argument with the base name of the command, prefixed by a dash:

transform[0] ${^} s,.*/,-,

For instance, if the command name is ‘/bin/bash’, ‘argv[0]’ will become ‘-bash’.

The transformation expression, expr, is a sed-like replace expression of the form:

s/regexp/replace/[flags]

where regexp is a regular expression, replace is a replacement for each part of the input that matches regexp. Both regexp and replace are described in detail in The ‘s’ Command in GNU sed.

As in sed, you can give several replace expressions, separated by a semicolon.

Supported flags are:

g

Apply the replacement to all matches to the regexp, not just the first.

i

Use case-insensitive matching

x

regexp is an extended regular expression (see Extended regular expressions in GNU sed).

number

Only replace the numberth match of the regexp.

Note: the POSIX standard does not specify what should happen when you mix the ‘g’ and number modifiers. Rush follows the GNU sed implementation in this regard, so the interaction is defined to be: ignore matches before the numberth, and then match and replace all matches from the numberth on.

Any delimiter can be used in lieu of ‘/’, the only requirement being that it be used consistently throughout the expression. For example, the following two expressions are equivalent:

transform s/one/two/
transform s,one,two,

Changing delimiters is often useful when the regex contains slashes. For instance, it is more convenient to write s,/,-, than s/\//-/.

For example, the following rule uses transform to ensure that /usr/bin/cvs binary is used:

rule cvs
  command ^cvs server
  transform[0] s|.*|/usr/bin/cvs|

The same effect can be achieved with a set statement, as shown in set-command.

As a more complex example, consider the following rule:

rule svn
  command ^svnserve -t
  transform s|-r *[^ ]*||;s|^svnserve |/usr/bin/svnserve -r /svnroot |

This transform expression first removes all occurrences of -r option and its arguments from the command line, and then adds its own -r option and replaces ‘svnserve’ with the full program file name.

GNU Rush legacy configuration syntax (split by node):   Section:   Chapter:FastBack: Rule   Up: Transformations   FastForward: Include   Contents: Table of ContentsIndex: Concept Index