1cdf0e10cSrcweir:
2cdf0e10cSrcweir    eval 'exec perl -S $0 ${1+"$@"}'
3cdf0e10cSrcweir        if 0;
4*7e90fac2SAndrew Rist#**************************************************************
5*7e90fac2SAndrew Rist#
6*7e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
7*7e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
8*7e90fac2SAndrew Rist#  distributed with this work for additional information
9*7e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
10*7e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
11*7e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
12*7e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
13*7e90fac2SAndrew Rist#
14*7e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
15*7e90fac2SAndrew Rist#
16*7e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
17*7e90fac2SAndrew Rist#  software distributed under the License is distributed on an
18*7e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*7e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
20*7e90fac2SAndrew Rist#  specific language governing permissions and limitations
21*7e90fac2SAndrew Rist#  under the License.
22*7e90fac2SAndrew Rist#
23*7e90fac2SAndrew Rist#**************************************************************
24*7e90fac2SAndrew Rist
25*7e90fac2SAndrew Rist
26cdf0e10cSrcweir#
27cdf0e10cSrcweir# Create ordinary theme from HiContrast images.
28cdf0e10cSrcweir#
29cdf0e10cSrcweir
30cdf0e10cSrcweiruse File::Copy;
31cdf0e10cSrcweiruse File::Find;
32cdf0e10cSrcweiruse File::Path;
33cdf0e10cSrcweiruse File::Spec;
34cdf0e10cSrcweir
35cdf0e10cSrcweir( $src, $dst ) = @ARGV;
36cdf0e10cSrcweir
37cdf0e10cSrcweirif ( $src eq "" || $dst eq "" ) {
38cdf0e10cSrcweir    print STDERR "Usage: hicontrast-to-theme.pl src dest\n\n";
39cdf0e10cSrcweir    print STDERR "Create ordinary theme from HiContrast images.\n";
40cdf0e10cSrcweir    exit 1;
41cdf0e10cSrcweir}
42cdf0e10cSrcweir
43cdf0e10cSrcweir$dst = File::Spec->rel2abs( $dst );
44cdf0e10cSrcweir
45cdf0e10cSrcweir@hc_table = (
46cdf0e10cSrcweir    [ ".*_h.png",         "_h.png",    ".png" ],
47cdf0e10cSrcweir    [ ".*_sch.png",       "_sch.png",  ".png" ],
48cdf0e10cSrcweir    [ ".*_hc.png",        "_hc.png",   ".png" ],
49cdf0e10cSrcweir    [ "lch_.*.png",       "lch_",      "lc_" ],
50cdf0e10cSrcweir    [ "sch_.*.png",       "sch_",      "sc_" ],
51cdf0e10cSrcweir    [ "lch[0-9].*.png",   "lch",       "lc" ],
52cdf0e10cSrcweir    [ "sch[0-9].*.png",   "sch",       "sc" ],
53cdf0e10cSrcweir    [ "loh[0-9].*.png",   "loh",       "lo" ],
54cdf0e10cSrcweir    [ "lxh[0-9].*.png",   "lxh",       "lx" ],
55cdf0e10cSrcweir    [ "sxh[0-9].*.png",   "sxh",       "sx" ],
56cdf0e10cSrcweir    [ "avh[0-9].*.png",   "avh",       "av" ],
57cdf0e10cSrcweir    [ "avlh[0-9].*.png",  "avlh",      "avl" ],
58cdf0e10cSrcweir    [ "idh[0-9].*.png",   "idh",       "id" ],
59cdf0e10cSrcweir    [ "imh[0-9].*.png",   "imh",       "im" ],
60cdf0e10cSrcweir    [ "mih[0-9].*.png",   "mih",       "mi" ],
61cdf0e10cSrcweir    [ "tbh[0-9].*.png",   "tbh",       "tb" ],
62cdf0e10cSrcweir    [ "nah[0-9].*.png",   "nah",       "na" ],
63cdf0e10cSrcweir    [ "nch[0-9].*.png",   "nch",       "nc" ],
64cdf0e10cSrcweir    [ "nvh[0-9].*.png",   "nvh",       "nv" ],
65cdf0e10cSrcweir    [ "ouh[0-9].*.png",   "ouh",       "ou" ],
66cdf0e10cSrcweir    [ "ddh[0-9].*.png",   "ddh",       "dd" ],
67cdf0e10cSrcweir    [ "sfh[0-9].*.png",   "sfh",       "sf" ],
68cdf0e10cSrcweir    [ "srh[0-9].*.png",   "srh",       "sr" ],
69cdf0e10cSrcweir    [ "wrh[0-9].*.png",   "wrh",       "wr" ],
70cdf0e10cSrcweir    [ "alh[0-9].*.png",   "alh",       "al" ],
71cdf0e10cSrcweir    [ "ath[0-9].*.png",   "ath",       "at" ],
72cdf0e10cSrcweir    [ "bih[0-9].*.png",   "bih",       "bi" ],
73cdf0e10cSrcweir    [ "coh[0-9].*.png",   "coh",       "co" ],
74cdf0e10cSrcweir    [ "foh[0-9].*.png",   "foh",       "fo" ],
75cdf0e10cSrcweir    [ "fuh[0-9].*.png",   "fuh",       "fu" ],
76cdf0e10cSrcweir    [ "oph[0-9].*.png",   "oph",       "op" ],
77cdf0e10cSrcweir    [ "unh[0-9].*.png",   "unh",       "un" ],
78cdf0e10cSrcweir    [ "edh[0-9].*.png",   "edh",       "ed" ],
79cdf0e10cSrcweir    [ "cdh[0-9].*.png",   "cdh",       "cd" ],
80cdf0e10cSrcweir    [ "frh[0-9].*.png",   "frh",       "fr" ],
81cdf0e10cSrcweir    [ "fwh[0-9].*.png",   "fwh",       "fw" ],
82cdf0e10cSrcweir    [ "nuh[0-9].*.png",   "nuh",       "nu" ],
83cdf0e10cSrcweir    [ "prh[0-9].*.png",   "prh",       "pr" ],
84cdf0e10cSrcweir    [ "shh[0-9].*.png",   "shh",       "sh" ],
85cdf0e10cSrcweir    [ "trh[0-9].*.png",   "trh",       "tr" ],
86cdf0e10cSrcweir    [ "reh[0-9].*.png",   "reh",       "re" ],
87cdf0e10cSrcweir    [ "joh[0-9].*.png",   "joh",       "jo" ],
88cdf0e10cSrcweir    [ "fph[0-9].*.png",   "fph",       "fp" ],
89cdf0e10cSrcweir    [ "dah[0-9].*.png",   "dah",       "da" ]
90cdf0e10cSrcweir);
91cdf0e10cSrcweir
92cdf0e10cSrcweirmy (@from_stat, @to_stat);
93cdf0e10cSrcweir
94cdf0e10cSrcweirsub copy_normalized {
95cdf0e10cSrcweir    $file = $_;
96cdf0e10cSrcweir    for $hc ( @hc_table ) {
97cdf0e10cSrcweir        ( $what, $from, $to ) = @$hc;
98cdf0e10cSrcweir        if ( $file =~ /$what/&&!($file=~/\.svn/) ) {
99cdf0e10cSrcweir            my $dir = File::Spec->catdir( $dst, $File::Find::dir );
100cdf0e10cSrcweir
101cdf0e10cSrcweir            if ( ! -d $dir ) {
102cdf0e10cSrcweir                mkpath( $dir );
103cdf0e10cSrcweir            }
104cdf0e10cSrcweir
105cdf0e10cSrcweir            ( my $copy = $file ) =~ s/$from/$to/;
106cdf0e10cSrcweir            $copy = File::Spec->catfile( $dir, $copy );
107cdf0e10cSrcweir
108cdf0e10cSrcweir	        @from_stat = stat($file);
109cdf0e10cSrcweir	        @to_stat = stat($copy);
110cdf0e10cSrcweir			if ( $from_stat[9] > $to_stat[9] ) {
111cdf0e10cSrcweir	            copy( $file, $copy ) || die $!;
112cdf0e10cSrcweir				utime( $from_stat[9], $from_stat[9], $copy );
113cdf0e10cSrcweir			}
114cdf0e10cSrcweir
115cdf0e10cSrcweir            last;
116cdf0e10cSrcweir        }
117cdf0e10cSrcweir    }
118cdf0e10cSrcweir}
119cdf0e10cSrcweir
120cdf0e10cSrcweirchdir( $src );
121cdf0e10cSrcweirfind( \&copy_normalized, '.' );
122