#!/usr/bin/env bash

set -e 

if (( $# == 2 ))
then
    PKG=`rospack find $1`
    FILENAME=$PKG/msg/$2.msg
    rosrun genmsg_cpp genmsg_lisp $FILENAME
    rosrun roslisp genmsg_lisp.py $FILENAME

    NAME="$2.lisp"
    echo "  $NAME"
    diff -w $PKG/msg/lisp/$1/$NAME $PKG/msg_gen/lisp/$NAME | head -n 50

    NAME="_package_$2.lisp"
    echo "  $NAME"
    diff -w $PKG/msg/lisp/$1/$NAME $PKG/msg_gen/lisp/$NAME | head -n 50
    
elif (( $# == 1 ))
then
    for p in `rosmsg package $1`
    do args=`echo $p | tr "/" " "`
       echo "$p"
       $0 $args
       echo "--------------------------------------"
    done
    PKG=`rospack find $1`
    echo "_package.lisp"
    diff -w $PKG/msg/lisp/$1/_package.lisp $PKG/msg_gen/lisp/_package.lisp | head -n 50
    NAME="$1-msg.asd"
    echo "$NAME"
    diff -w $PKG/msg/lisp/$1/$NAME $PKG/msg_gen/lisp/$NAME | head -n 50

else
    echo "Usage: test-genmsg-lisp PKG MSG or test-genmsg-lisp PKG"
    exit 1
fi

