The <arg> element only appears as a child of the <format> element, and appears after the <fstring> element. It is used to specify an argument to the formatted string. Multiple arguments may be specified.
<arg> is a simple element. It has no attributes and contains an Expression.
<xddl>
<type id="val">
<format>
<fstring>The value is %d.</fstring>
<arg>first</arg>
</format>
</type>
<structure>
<field name="first" length="8" type="#val"/>
<field name="second" length="8" type="#val"/>
</structure>
</xddl>
simple_arg.xddl
# idm simple_arg.xddl 0405
Name Length Value Hex Description
first 8 4 04 The value is 4.
second 8 5 05 The value is 4.
In the example above, the <format> has one argument, first. This means
that wherever the val type is used, there must be a field (or property)
called first in context.
As you can see, this causes a problem for the second field. It's
description is using the same format string, and thus showing the wrong
value. We could make another type for the second field, or we can use
the special $$ variable.
The special $$ variable represents the current value that is being
evaluated. If we replace the argument above with <arg>$$</arg>, we get:
And if we parse the same message:
# idm dollar.xddl 0405
No such file: dollar.xddl
As you can see, the description is correct for both fields.
The following example illustrates the use of multiple arguments.
<xddl>
<type id="add">
<format>
<fstring>%d + %d = %d</fstring>
<arg>first</arg>
<arg>second</arg>
<arg>first + second</arg>
</format>
</type>
<structure>
<field name="first" length="8"/>
<field name="second" length="8" type="#add"/>
</structure>
</xddl>
advanced.xddl
Remember, arguments can be any XDDL Expression, so the addition in the third argument is perfectly valid.
# idm advanced.xddl 0102
Name Length Value Hex Description
first 8 1 01
second 8 2 02 1 + 2 = 3
See the <type> element for more example usage.