# PARSECOM.PM
#
# Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
#


# General Command-Line processing utility
# ----------------------------------------

package Parsecom;

require Exporter;
@ISA=qw(Exporter);

@EXPORT=qw(
	Com_ParseL
);


sub Com_ParseL (@) {

# subroutine takes a hash reference to fill with flags and their parameters,
# then an array ref to fill with command-line arguments, then a list of switches
# not taking arguments then a list of switches taking arguments

	my ($CLFlagHRef,$CLArgARef,$FlagARef,$FlagArgARef)=@_;
	my $Flag;
	my $Elem;
	my $Switch;
	my $FlagArg;
	ARGV: foreach $Elem (@ARGV) {
		$Switch=$Elem;
		if ($Switch=~/^(\-|\/)(\S*)$/o) {
			$Switch=$2;
			$FlagArg='';
			# reverse so longer flags beginning with same letters tried first
			foreach $Flag (@$FlagArgARef) {
				if ($Switch=~/^$Flag$/i) {
					$FlagArg=$Flag;
					next ARGV;
				}
			}
			foreach $Flag (@$FlagARef) {
				if ($Switch=~/^$Flag$/i) {
					${%$CLFlagHRef}{$Flag}=1;
					next ARGV;
				}
			}
			die "\nERROR: Unknown Flag \"$Elem\"\n";
		}
		if ($FlagArg) {
			${%$CLFlagHRef}{$FlagArg}=$Elem;
			$FlagArg='';
			next ARGV;
		}
		push @$CLArgARef,$Elem;
	}
	undef $Switch;
	undef $Elem;
	undef $FlagArg;
	undef $Flag;
}

1;

