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

RCS_ID='$Id: nsq-lock,v 1.1 1998/05/29 20:34:03 carlos Exp $'

my_name=$(basename $0)

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.

NoSQL replacement for 'lockfile', 'shlock' or other file locking
utilities (which usage is recommended over this script), for those
systems that do not provide them. 'lockfile' is normally distributed
with the 'procmail' mail filtering system. 'shlock' is part of the
'innd' Usenet News server.

Note: "file" MUST end with ".LCK", i.e., if the table being locked
is "table.rdb", then "file" must be "table.rdb.LCK". The ".LCK"
suffix is not provided automatically to make the ${my_name} behaviour
consistent with that of the aforementioned external locking programs.

This utility accepts (and ignores) any extra command line options,
apart from '-help', so that will not complain on extra 'lockfile'
options.

$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., 59 Temple Place Suite 330, Boston, MA 02111-1307
USA.
			----------------------

_EOH_
		exit 0
		;;
	-*) shift ;;
	*)  
		# Use mode 000 for lock files.
		umask 777

		for i in 1 2 3 4 5 6 7 8 9
		do
			if test ! -f $1
			then
				>$1
				trap_list="${trap_list} $1"
				trap "rm -f ${trap_list}" 1 2 3 11 13 15
				shift
				break
			else
				sleep 1
			fi
		done
		test $i -eq 9 && exit 1
		;;
  esac
done

exit 0

