Appendix A. Writing Mapping Expressions

This appendix contains these sections:

About Mapping Expressions

By writing effective expressions, you can gather files with different names from anywhere and pull them together into one subsystem, or qualify which files with a particular IDB tag go into a subsystem.

Although you can usually make these changes by changing your product structure and tags using the swpkg worksheets, you might occasionally prefer instead to add mapping expressions directly to the spec file. Mapping expressions are typically used when you have a very complex existing spec file in which you need to change the file-to-subsystem mappings—but you do not want to completely overhaul the spec file.

You can change the file-to-subsystem mappings by typing valid mapping expressions into the Mappings text field in the Complete Product Hierarchy worksheet. This appendix explains the “expressions language” used to create valid mapping expressions.


Note: Using expressions can cause problems because subsystem names can change, breaking the intended behavior. Silicon Graphics recommends that you introduce expressions carefully, and only when absolutely necessary.


Variables and Data Types

Values are typed as integer or string—non-zero integers and non-null strings are considered “true” in boolean tests. A reference to an IDB attribute is “true” if the IDB attribute is present in the database record being operated on.

References to IDB attribute arguments are made with a form of subscripting after the argument name, where a list of integers (or integers separated by ``..'' indicating a range) selects specific arguments. The variable argc within brackets refers to the last argument. The selected arguments are concatenated with separating spaces and returned as a string value. (Note that the mechanisms of IDB attribute reference just described are likely to change. They are not terribly useful as is.)

Integer and string variables and constants are available, with single and double quotes being entirely equivalent around string constants.

Operators

The primary values may be combined with most of the usual operators, which behave as in C unless otherwise noted:

+

add

-

subtract

*

multiply

/

divide

=~

pattern match

!=

pattern not match

//

substring

::

concatenation

&

bitwise and

|

bitwise or

^

bitwise exclusive or

~

bitwise (unary) not

&&

logical and

||

logical or

!

logical not

!=

not equal comparison (on integers or strings)

==

equal comparison (on integers or strings)

<=

less than or equal comparison (on integers or strings)

>=

greater than or equal comparison (on integers or strings)

<

less than comparison (on integers or strings)

>

greater than comparison (on integers or strings)

? :

conditional

=

assignment

,

expression list

Parenthesis for grouping are also available.

Built in Variables

type 

The file type as a one-character string; the first character of file, directory, block device, character device, (symbolic) link, or (named) pipe (that is, FIFO).

mode 

Permission bits. The type of this value is integer, but is converted to a string according to context (though it's a decimal integer, which is probably not what you want).

owner 

The name of the owner. The UID is mapped through etc/passwd.

group 

The name of the group. The GID is mapped through etc/group.

dstpath 

The relative (to root) pathname of the file in the software product destination tree.

srcpath 

The relative pathname of the file in the source tree.

nattr 

The integer number of IDB attributes associated with the record being operated on.

argc 

(Defined only within IDB attribute argument list references.) The number of arguments for the current IDB attribute.

sbase 

The pathname of the root of the source tree.

rbase 

The pathname of the root of the destination tree.

IDB 

The pathname of the primary IDB file. When files are accessed, the mapping between user and group integer IDs and the owner and group string values in the IDB are based on the etc/passwd and etc/group files, respectively. These are first sought under sbase, then under rbase, then under /.

Built-In Functions

spath(s) 

Returns an absolute pathname for the argument; if the given value is relative, it is concatenated with the value of sbase. This is useful in converting a srcpath value into an absolute pathname.

rpath(s) 

Returns an absolute destination pathname, concatenated with the value of rbase.

putrec() 

Prints the current record in standard format (that is, on one line, packed).

printf(f,a...) 

Formatted print (subset of stdio printf). Recognizes field widths with leading zero pad indicator, types %s, %d, %o.

print(a...) 

Unformatted print. Prints values as decimal integers or strings, separated by spaces, terminated with newline.

bytes(s) 

Returns the size, in bytes, of the given file, or -1 if not found.

blocks(s) 

Returns the size, in blocks, of the given file, or -1 if not found.

access(s,m) 

Returns the value of the access(2) system call.

Statements

The following statements are implemented as in C: if [ else ], while, for, break, continue, return, grouping with braces, and expressions.

Example

The basic spec file for rfind doesn't follow the recommendation that each software subsystem have a matching reference page system. Instead, a single IDB tag was used for all reference pages. You could use this expression to put the .1 reference pages into one subsystem and the .1m reference pages into another:

exp 'rfind.man.rfind && srcpath =~ "*.1"' 
exp 'rfind.man.rfind && srcpath =~ "*.1m"'