summaryrefslogtreecommitdiff
path: root/solenv/bin/converttags.pl
blob: aa2fe63c6ce86c2588b7eba66dd3c34c8d0a2896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# converttags - a perl script to coonvert some predefined tags
# to user specified values
#
# Copyright 2000, 2010 Oracle and/or its affiliates.
#

if($#ARGV == -1)
{
    die "No parameters were specified.\nperl converttags.pl <mode> <title> <productname> [<color1>] [<color2>] file_1 [... file_n]\n";
}
if($#ARGV < 2)
{
    die "No file were specified -> no file must be converted!\n";
}

# mode = 1 -> convert
#      = 2 -> exit without conversion
$mode = shift @ARGV;

$title = shift @ARGV;
$productname = shift @ARGV;

$color1 = "";
$color2 = "";

if( $mode =~ s/2/$1/go )
{
    exit 0;
}

if( $ARGV[0] =~ s/(#[\w]{6})/$1/go )
{
    $color1 = shift @ARGV;
}
if( $ARGV[0] =~ s/(#[\w]{6})/$1/go )
{
    $color2 = shift @ARGV;
}

print "$title\n";
print "$productname\n";
print "$color1\n";
print "$color2\n";

$return = 0;

while (@ARGV)
{
    my $lineCount = 0;
    $ARGV = shift @ARGV;
    print "convert tags: $ARGV ";

    open ( FILEIN, $ARGV ) || die "could not open $ARGV for reading";
    @lines = <FILEIN>;
    close( FILEIN );
    open( FILEOUT, ">$ARGV.tmp" ) || die "could not open $ARGV.tmp for writing";


    foreach $_ (@lines)
    {
    $lineCount++;
    if ( $lineCount == 10 )
    {
        $lineCount = 0;
        print ".";
    }
    # change [TITLE] tag
    s#\[TITLE\]#$title#go;

    # change [PRODUCTNAME] tag
    s#\[PRODUCTNAME\]#$productname#go;

    # change color #003399 to #$color1 if color1 was specified!
    if ( ! "$color1" eq "" )
    {
        s/#003399/$color1/go;
    }

    # change color #99CCFF to #$color2 if color2 was specified!
    if ( ! "$color2" eq "" )
    {
        s/#99CCFF/$color2/go;
    }
    print FILEOUT $_;
    }
    print " OK\n";

    close FILEOUT;
    chmod 0666, $ARGV;
    rename "$ARGV.tmp", $ARGV || die "could not rename $ARGV.tmp to $ARGV";
}

exit $return;