#!/bin/bash
# vim:set sw=4 ts=4:
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005           SUSE GmbH, Nuernberg, Germany
#
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: 
#	rpmlist
#	Copyright (c) 2004 SuSE Linux AG. All rights reserved.
#	Gnu Public License (GPL)

INP="cat $2"

case $1 in
	-h)
		echo -e "usage: rpmlist OPTION file|-\n"
		echo "OPTION is one of:"
		echo "	-c	show name as snippet for control file"
		echo "	-n	show name"
#		echo "	-m	show name, major version"
		echo "	-v	show name, version"
		echo "	-b	show name, version, build number"
		echo "	-l	show name, version, build number from ls"
		echo "	-x	show name from control file"
#		echo "	-s	show name from selection file"
		echo "	-h	show this help"
		echo -e "\nIf a single dash (-) is given as file, stdin is taken."
		exit 1
	;;
	-a)
		$INP
	;;
	-v)
		$INP |\
		/usr/bin/awk -F"-" '{
		for (i=1; i<NF-1; i++) {
			printf "%s-", $i
			}; printf "%s\n", $i;
		}'
	;;
#	-m)
#		$INP |\
#		/usr/bin/awk -F"-" '{
#		for (i=1; i<NF-1; i++) {
#			printf "%s-", $i
#			}; printf "%s\n", $i;
#		}'
#	;;
	-n)
		$INP |\
		/usr/bin/awk -F"-" '{
		for (i=1; i<NF-2; i++) {
			printf "%s-", $i
			}; printf "%s\n", $i;
		}'
	;;
	-c)
		$INP |\
		/usr/bin/awk -F"-" '{
		printf "<package>"
		for (i=1; i<NF-2; i++) {
			printf "%s-", $i
			}; printf "%s</package>\n", $i;
		}'
	;;
	-l)
		$INP |\
		/usr/bin/awk -F"." '{
		for (i=1; i<NF-2; i++) {
			printf "%s.", $i
			}; printf "%s\n", $i;
		}'
	;;	
	-x)
		$INP |\
		sed s/"<package>"// | sed s/"<\/package>"//
	;;
#	-s)
#		$INP |\ 
#	;;
esac
#
