#!/bin/sh
#
# Built-in table locking program for NoSQL.
#
# Author: C.Strozzi <carlos@linux.it>

RCS_ID='$Id: nsq-lock,v 0.9 1998/03/04 09:12:49 carlos Exp $'

my_name=$(basename $0)

# Use mode 000 for lock files.
umask 777

while [ $# -ge 1 ] ; do
  case $1 in
	-h*) cat <<_EOH_

        NoSQL utility: ${my_name}

Usage:  ${my_name}  [options]  file [ file ... ]

Options:
    -h    Print this help info.

Built-in NoSQL replacement for the 'lockfile' utility,
for those systems that do not provide the latter.
Lockfile is normally distributed with the 'procmail'
mail filtering system, and its usage is recommended
over this script.

This utility accepts (and ignores) any command line options
(except -h), for better compatibility with the real 'lockfile'.

$RCS_ID

			----------------------
NoSQL RDBMS, Copyright (C) 1998 Carlo Strozzi.
This program comes with ABSOLUTELY NO WARRANTY; for details
refer to the GNU General Public License.

You should have received a copy of the GNU General Public License
along with this program;  if not, write to the Free Software
Foundation, Inc., 675 Mass Ave., Cambridge, MA 02139, USA.
			----------------------

_EOH_
		exit 0
		;;
	-*) shift ;;
	*)  
		for i in 1 2 3 4 5 6 7 8 9
		do
			if [ ! -f $1 ]
			then
				>$1
				trap_list="${trap_list} $1"
				trap "rm -f ${trap_list} 2>/dev/null" 1 2 15
				shift
				break
			else
				sleep 1
			fi
		done
		[ $i -eq 9 ] && exit 1
		;;
  esac
done

exit 0

