xref: /aoo41x/main/solenv/bin/converttags.pl (revision 841807c9)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21#
22# converttags - a perl script to coonvert some predefined tags
23# to user specified values
24#
25
26if($#ARGV == -1)
27{
28    die "No parameters were specified.\nperl converttags.pl <mode> <title> <productname> [<color1>] [<color2>] file_1 [... file_n]\n";
29}
30if($#ARGV < 2)
31{
32    die "No file were specified -> no file must be converted!\n";
33}
34
35# mode = 1 -> convert
36#      = 2 -> exit without conversion
37$mode = shift @ARGV;
38
39$title = shift @ARGV;
40$productname = shift @ARGV;
41
42$color1 = "";
43$color2 = "";
44
45if( $mode =~ s/2/$1/go )
46{
47    exit 0;
48}
49
50if( $ARGV[0] =~ s/(#[\w]{6})/$1/go )
51{
52    $color1 = shift @ARGV;
53}
54if( $ARGV[0] =~ s/(#[\w]{6})/$1/go )
55{
56    $color2 = shift @ARGV;
57}
58
59print "$title\n";
60print "$productname\n";
61print "$color1\n";
62print "$color2\n";
63
64$return = 0;
65
66while (@ARGV)
67{
68    my $lineCount = 0;
69    $ARGV = shift @ARGV;
70    print "convert tags: $ARGV ";
71
72    open ( FILEIN, $ARGV ) || die "could not open $ARGV for reading";
73    @lines = <FILEIN>;
74    close( FILEIN );
75    open( FILEOUT, ">$ARGV.tmp" ) || die "could not open $ARGV.tmp for writing";
76
77
78    foreach $_ (@lines)
79    {
80	$lineCount++;
81	if ( $lineCount == 10 )
82	{
83	    $lineCount = 0;
84	    print ".";
85	}
86	# change [TITLE] tag
87	s#\[TITLE\]#$title#go;
88
89	# change [PRODUCTNAME] tag
90	s#\[PRODUCTNAME\]#$productname#go;
91
92	# change color #003399 to #$color1 if color1 was specified!
93	if ( ! "$color1" eq "" )
94	{
95	    s/#003399/$color1/go;
96	}
97
98	# change color #99CCFF to #$color2 if color2 was specified!
99	if ( ! "$color2" eq "" )
100	{
101	    s/#99CCFF/$color2/go;
102	}
103	print FILEOUT $_;
104    }
105    print " OK\n";
106
107    close FILEOUT;
108    chmod 0666, $ARGV;
109    rename "$ARGV.tmp", $ARGV || die "could not rename $ARGV.tmp to $ARGV";
110}
111
112exit $return;
113