#!/bin/sh
#	program:	netkillzeros
#	release:	1.5.0
#	input:		one (possibly zero-filled) 4-octet network address
#			on the command line.
#	output:		some dot-separated octets representing the same net,
#			where zero octets have been removed from the right end.
#	example:	"134.114.0.0" -> "134.114"
#	example:	"128.0.12.0" -> "128.0.12"
#	exit value:	0 if nothing goes wrong, 1 if something did.
#
# Copyright (C) 1993-2000 Paul A. Balyoz <pab@domtools.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    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.
#

AWK=/usr/local/domtools/lib/netkillzeros.awk

if test $# -ne 1; then
	echo "usage: $0 netzeroaddress" >&2
	echo 'ERROR'
	exit 1
fi

net=`echo $1 | awk -F. -f $AWK`
status=$?

if test $status -ne 0; then
	status=1
else
	echo $net
fi

if test $status -ne 0; then
	echo 'ERROR'
fi

exit $status
