#!/usr/bin/perl
# Copyright (c) 2002 SuSE GmbH Nuernberg, Germany.  All rights reserved.
#
# Author: Marcus Schaefer <sax@suse.de>, 2002
# xapi script: split special RawData option list
# --
#
# CVS ID:
# --------
# Status: Up-to-date
#
use strict;
use Env;

#---[ CheckSplit ]----#
sub CheckSplit {
#------------------------------------------------------
# check if a splitted list with seperator [,] was
# splitted in a correct way. This function will check
# for the number ["] signs and make sure there was
# no split between optionslist which mustn't splitted
#
	my @list   = @_;
	my @result = ();
	my $count  = 0;
	my $joined;
	for (my $i=0;$i<@list;$i++) {
		my $signs = countDoubleQuote ($list[$i]);
		if ( ($signs == 0) || ($signs % 2 != 0) ) {
			$joined.=",$list[$i]";
		} else {
			$result[$count] = $list[$i];
			$count++;
			if ($joined ne "") {
				$joined =~ s/^,//;
				$result[$count] = $joined;
				$joined = "";
				$count++;
			}
		}
	}
	@list   = @result;
	@result = ();
	foreach (@list) {
	if (defined $_) {
		push (@result,$_);
	}
	}
	return @result;
}

#---[ countDoubleQuote ]----#
sub countDoubleQuote {
#---------------------------------------
# count double quotes in a string and
# return the result
#
	my $str = $_[0];
	my $cnt = 0;
	while (length ($str)) {
		if (chop($str) eq "\"") {
			$cnt++;
		}
	}
	return $cnt;
}


my @list = ();
@list = split (/,/,$ARGV[0]);
@list = CheckSplit (@list);

my $result = join ("|",@list);
print "$result\n";
