1*9780544fSAndrew Rist#**************************************************************
2*9780544fSAndrew Rist#
3*9780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*9780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*9780544fSAndrew Rist#  distributed with this work for additional information
6*9780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*9780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*9780544fSAndrew Rist#  "License"); you may not use this file except in compliance
9*9780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10*9780544fSAndrew Rist#
11*9780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*9780544fSAndrew Rist#
13*9780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*9780544fSAndrew Rist#  software distributed under the License is distributed on an
15*9780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
17*9780544fSAndrew Rist#  specific language governing permissions and limitations
18*9780544fSAndrew Rist#  under the License.
19*9780544fSAndrew Rist#
20*9780544fSAndrew Rist#**************************************************************
21*9780544fSAndrew Rist
22*9780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir
25cdf0e10cSrcweirpackage par2script::converter;
26cdf0e10cSrcweir
27cdf0e10cSrcweiruse par2script::remover;
28cdf0e10cSrcweir
29cdf0e10cSrcweir#############################
30cdf0e10cSrcweir# Converter
31cdf0e10cSrcweir#############################
32cdf0e10cSrcweir
33cdf0e10cSrcweirsub convert_array_to_hash
34cdf0e10cSrcweir{
35cdf0e10cSrcweir	my ($arrayref) = @_;
36cdf0e10cSrcweir
37cdf0e10cSrcweir	my ($line, $key, $value);
38cdf0e10cSrcweir
39cdf0e10cSrcweir	my %newhash = ();
40cdf0e10cSrcweir
41cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
42cdf0e10cSrcweir	{
43cdf0e10cSrcweir		$line = ${$arrayref}[$i];
44cdf0e10cSrcweir
45cdf0e10cSrcweir		if ( $line =~ /^\s*(\w+?)\s+(.*?)\s*$/ )
46cdf0e10cSrcweir		{
47cdf0e10cSrcweir			$key = $1;
48cdf0e10cSrcweir			$value = $2;
49cdf0e10cSrcweir			$newhash{$key} = $value;
50cdf0e10cSrcweir		}
51cdf0e10cSrcweir	}
52cdf0e10cSrcweir
53cdf0e10cSrcweir	return \%newhash;
54cdf0e10cSrcweir}
55cdf0e10cSrcweir
56cdf0e10cSrcweirsub convert_hash_into_array
57cdf0e10cSrcweir{
58cdf0e10cSrcweir	my ($hashref) = @_;
59cdf0e10cSrcweir
60cdf0e10cSrcweir	my @array = ();
61cdf0e10cSrcweir	my ($key, $value, $input);
62cdf0e10cSrcweir
63cdf0e10cSrcweir	foreach $key (keys %{$hashref})
64cdf0e10cSrcweir	{
65cdf0e10cSrcweir		$value = $hashref->{$key};
66cdf0e10cSrcweir		$input = "$key = $value\n";
67cdf0e10cSrcweir		push(@array ,$input);
68cdf0e10cSrcweir	}
69cdf0e10cSrcweir
70cdf0e10cSrcweir	return \@array
71cdf0e10cSrcweir}
72cdf0e10cSrcweir
73cdf0e10cSrcweirsub convert_stringlist_into_array_2
74cdf0e10cSrcweir{
75cdf0e10cSrcweir	my ( $input, $separator ) = @_;
76cdf0e10cSrcweir
77cdf0e10cSrcweir	my @newarray = ();
78cdf0e10cSrcweir	my $first = "";
79cdf0e10cSrcweir	my $last = "";
80cdf0e10cSrcweir
81cdf0e10cSrcweir	$last = $input;
82cdf0e10cSrcweir
83cdf0e10cSrcweir	while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/)	# "$" for minimal matching
84cdf0e10cSrcweir	{
85cdf0e10cSrcweir		$first = $1;
86cdf0e10cSrcweir		$last = $2;
87cdf0e10cSrcweir		par2script::remover::remove_leading_and_ending_whitespaces(\$first);
88cdf0e10cSrcweir		if ( $first ) { push(@newarray, $first); }
89cdf0e10cSrcweir	}
90cdf0e10cSrcweir
91cdf0e10cSrcweir	par2script::remover::remove_leading_and_ending_whitespaces(\$last);
92cdf0e10cSrcweir	if ( $last ) { push(@newarray, $last); }
93cdf0e10cSrcweir
94cdf0e10cSrcweir	return \@newarray;
95cdf0e10cSrcweir}
96cdf0e10cSrcweir
97cdf0e10cSrcweirsub convert_stringlist_into_array
98cdf0e10cSrcweir{
99cdf0e10cSrcweir	my ( $includestringref, $separator ) = @_;
100cdf0e10cSrcweir
101cdf0e10cSrcweir	my @newarray = ();
102cdf0e10cSrcweir	my ($first, $last);
103cdf0e10cSrcweir
104cdf0e10cSrcweir	$last = ${$includestringref};
105cdf0e10cSrcweir
106cdf0e10cSrcweir	while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/)	# "$" for minimal matching
107cdf0e10cSrcweir	{
108cdf0e10cSrcweir		$first = $1;
109cdf0e10cSrcweir		$last = $2;
110cdf0e10cSrcweir		par2script::remover::remove_leading_and_ending_whitespaces(\$first);
111cdf0e10cSrcweir		push(@newarray, $first);
112cdf0e10cSrcweir	}
113cdf0e10cSrcweir
114cdf0e10cSrcweir	par2script::remover::remove_leading_and_ending_whitespaces(\$last);
115cdf0e10cSrcweir	push(@newarray, $last);
116cdf0e10cSrcweir
117cdf0e10cSrcweir	return \@newarray;
118cdf0e10cSrcweir}
119cdf0e10cSrcweir
120cdf0e10cSrcweir#############################################################################
121cdf0e10cSrcweir# The file name contains for some files "/". If this programs runs on
122cdf0e10cSrcweir# a windows platform, this has to be converted to "\".
123cdf0e10cSrcweir#############################################################################
124cdf0e10cSrcweir
125cdf0e10cSrcweirsub convert_slash_to_backslash
126cdf0e10cSrcweir{
127cdf0e10cSrcweir	my ($filesarrayref) = @_;
128cdf0e10cSrcweir
129cdf0e10cSrcweir	my ($onefile, $filename);
130cdf0e10cSrcweir
131cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
132cdf0e10cSrcweir	{
133cdf0e10cSrcweir		$onefile = ${$filesarrayref}[$i];
134cdf0e10cSrcweir		$onefile->{'Name'} =~ s/\//\\/g;
135cdf0e10cSrcweir	}
136cdf0e10cSrcweir}
137cdf0e10cSrcweir
138cdf0e10cSrcweir1;
139