<'
lang c

# check arguments
if {[llength $argv] != 2} { error "expected arguments: component types" }
lassign $argv component types

# compute handy shortcuts
set comp [$component name]
set version [$component version]

if {[catch {$component doc} doc]} {
  set doc $comp
}

# quote for xml
proc quote { string } {
  string map {
    \" &quot; ' &apos;
    < &lt; > &gt;
    & &amp;
  } $string
}
'>
<package format="2" >
  <name><"$comp">_ros</name>
  <version><"[join [lrange [list {*}[split $version .] 0 0] 0 2] .]"></version>
  <description>
<"[quote $doc]">
  </description>
  <license>
<'if {![catch {dotgen input notice} notice]} {'>
<"[quote $notice]">
<'} else {'>
unknown
<'}'>
  </license>
<'if {![catch {$component email} email]} {'>
  <maintainer email="<"$email">" ><"$email"></maintainer>
<'} else {'>
  <maintainer email="unknown@example.com" >unknown</maintainer>
<'}'>
<'set deps [dict create] ;# use a dict to avoid duplicates'>
<'dict set deps roscpp {}'>
<'dict set deps std_msgs {}'>
<'dict set deps actionlib {}'>
<'dict set deps actionlib_msgs {}'>
<'foreach t $types {'>
<'  if {![catch {$t masquerade ros} masquerade]} {'>
<'    dict set deps [lindex [split $masquerade /] 0] {}'>
<'  }'>
<'}'>
<'foreach d [dict keys $deps] {'>
  <depend><"$d"></depend>
<'}'>
</package>
