The target definition file – Comtrol eCos User Manual

Page 779

Advertising
background image

Writing New Devices - host

}

The first call checks for a flag

-o13

or

--o13

- the code treats options with single and double hyphens inter-

changeably. The second call checks for an argument of the form

-mark=

<

value

>

or a pair of arguments

-mark

<

value

>

. The value part of a name/value pair can be obtained using synth::argv_get_value;

variable speed 1

if { [synth::argv_defined "-mark="] } {

set mark [synth::argv_get_value "-mark="]

if { ![string is integer $mark] || ($mark < 1) || ($mark > 9) } {

<

issue diagnostic

>

} else {

set speed $mark

}

}

synth::argv_get_value should only be used after a successful call to synth::argv_defined. At present there is no
support for some advanced forms of command line argument processing. For example it is not possible to repeat a
certain option such as

-v

or

--verbose

, with each occurrence increasing the level of verbosity.

If a script is going to have its own set of command-line arguments then it should give appropriate details if the user
specifies

--help

. This involves a hook function:

namespace eval my_device {

proc help_hook { } {

puts " -o13

: activate the omega 13 device"

puts " -mark

<

speed

>

: set speed. Valid values are 1 to 9."

}

synth::hook_add "help" my_device::help_hook

}

The Target Definition File

Most device scripts will want to check entries in the target definition file for run-time configuration information.
The Tcl procedures for this are as follows:

synth::tdf_has_device

<

name

>

synth::tdf_get_devices

synth::tdf_has_option

<

devname

> <

option

>

synth::tdf_get_option

<

devname

> <

option

>

synth::tdf_get_options

<

devname

> <

option

>

synth::tdf_get_all_options

<

devname

>

synth::tdf_has_device can be used to check whether or not the target definition file had an entry

synth_device

<

name

>

. Usually the name will match the type of device, so the

console.tcl

script will look

for a target definition file entry

console

. synth::tdf_get_devices returns a list of all device entries in the target

definition file.

Once it is known that the target definition file has an entry for a certain device, it is possible to check for options
within the entry. synth::tdf_has_option just checks for the presence, returning a boolean:

if { [synth::tdf_has_option "console" "appearance"] } {

675

Advertising