#!/bin/sh
####
# NAME
#	insert-executer - replace execution command after #!.
# VERSION
#	$Id$
# CHANGELOG
#	$Log$
# USAGE
#	insert-executer command1 command2 command3 ...
# DESCRIPTION
#  `insert-executer' command read standard-input and add/replace
#  the line "#!@command@". the @command@ is given by command line
#  argument of this command.
# COPYRIGHT
#  Copyright (C) 2000,2001 Steel Wheels Project.
#  This file is a apart of the papaya utilities. 
#  If you need the information of copyright of this file, see COPYING
#  file distributed with file or see http://www.asahi-net.or.jp/~em7t-hmd
#  web page.

THIS="insert-executer"

message(){
	echo "$THIS $1" >&2 ;
}

error(){
	echo "$THIS [ERROR] $1" >&2 ;
	exit 1 ;
}

# seach commands
if test "X$1" = "X" ; then
	error "command list is not given." ;
fi
COMMAND="" ;
for ONECOM in $* ; do
	if search-exec -n $ONECOM ; then
		if test "X$COMMAND" = "X" ; then
			COMMAND=`search-exec $ONECOM` ;
		fi
	fi
done
if test "X$COMMAND" = "X" ; then
	error "command is not found in command list \"$*\"" ;
fi

echo "#!$COMMAND"
grep -v "#!" ;

exit 0 ;

