#!/usr/bin/perl -s
# Convert a load of package files into mm input
# Presumes files are of the form:
# package=thingy
#   field=value
#   field=value
#   ...
#
# pkgs_to_mmin [-y min_restart_last_ok] [-n min_restart_last_notok] [packages]
#
# By Lee McLoughlin <lmjm@doc.ic.ac.uk>
#  You can do what you like with this except claim that you wrote it or
#  give copies with changes not approved by Lee.  Neither Lee nor any other
#  organisation can be held liable for any problems caused by the use or
#  storage of this package.
#
# $Id: pkgs_to_mmin,v 2.1 1993/06/28 15:22:32 lmjm Exp lmjm $
# $Log: pkgs_to_mmin,v $
# Revision 2.1  1993/06/28  15:22:32  lmjm
# Full 2.1 release
#
# Revision 1.1  1993/06/22  19:52:46  lmjm
# Initial revision
#
#

# Allow a day (more or less) before trying a site again.

$min_restart_last_ok = 20;
$min_restart_last_notok = 20;

while( $#ARGV >= 0 ){
	local( $arg ) = shift;

	# only bother with -flag's
	if( $arg !~ /^-/ ){
		unshift( ARGV, $arg );
		last;
	}

	if( $arg =~ /-y(.*)$/ ){
		local( $val ) = $1;
		if( length( $val ) == 0 ){
			# must be -y space number
			$val = shift;
		}
		$min_restart_last_ok = $1;
	}
	elsif( $arg =~ /-n(.*)$/ ){
		local( $val ) = $1;
		if( length( $val ) == 0 ){
			# must be -n space number
			$val = shift;
		}
		$min_restart_last_notok = $1;
	}
}

while( <> ){
	next if( /^#/ );
	chop;
	if( /^package=(.*)/ ){
		$package = $1;
		$package =~ s/^\s*//;
		$package =~ s/\s*$//;
	}
	if( /^\s*skip=/ ){
		$package = '';
	}
	if( eof || /^$/ ){
		if( $package ){
			$file = $ARGV;
			$file =~ s,.*/,,;
			print "$file:$package $min_restart_last_ok $min_restart_last_notok\n";
			$package = '';
		}
	}
}
