#!/bin/sh
# Copyright 2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
script_path=`dirname $0`
script_name=`basename $0`
cmd="set"
STATUS=0
test="";comment=" * "; new_comment=""; bug_id="";
usage="usage: $script_name [-h] [- <bug-id>] [-c <comment>] (file|dir)+"

while getopts "thc:i:" opt; do
  case $opt in
    t) test="test";;
    c) new_comment="$OPTARG";;
    i) bug_id="-bug-number $OPTARG";;
    h|\?)
      echo $usage;
      echo "    h for this help"
      echo "    c <comment>"
      echo "    i <bug-id>"
      exit 1;;
  esac
done
shift `expr $OPTIND - 1`

: echo $script_name: checking arguments...
if [ $# -eq 0 ]; then
  echo "nothing to $script_name"
  echo $usage
  exit 1
else
  : echo ok
fi

: echo prime $entry

eval `$script_path/findcomp2 $1`;
if [ -z "$compound" ]; then
  entry=;
  echo "cannot identify compound \"$1\""
  exit 1
elif [ -z "$unit" ]; then
  entry="-c $compound"
else
  entry="-c $compound -u $unit"
fi
shift

: echo stuff in the separators

for arg in $*; do
  eval `$script_path/findcomp2 $arg`;
  if [ -z "$compound" ]; then
    echo "cannot identify compound \"$arg\""
    exit 1
  elif [ -z "$unit" ]; then
    entry="$entry -a -c $compound"
  else
    entry="$entry -a -c $compound -u $unit"
  fi
done

: echo final processing

if [ -z "$entry" ]; then
  echo skipped everythin
elif [ -n "new_$comment" ]; then
  hope $test $cmd $bug_id -comment "$new_comment" $entry
else
  hope $test $cmd $bug_id -comment "$comment" $entry
fi

###############################################################################
# $Log: setcomment,v $
# Revision 1.3  1996/07/12 11:01:12  io
# [Bug #1463]
# beauty treatment and bug-ids
#
# Revision 1.2  1995/06/27  15:05:52  jont
# Add necessary paths
#
# Revision 1.1  1995/05/01  10:16:01  daveb
# new unit
# Tool for setting comment leaders in Hope files.
#
#
# Copyright 2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
