1*cdf0e10cSrcweir:
2*cdf0e10cSrcweir    eval 'exec perl -S $0 ${1+"$@"}'
3*cdf0e10cSrcweir        if 0;
4*cdf0e10cSrcweir#*************************************************************************
5*cdf0e10cSrcweir#
6*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7*cdf0e10cSrcweir#
8*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
9*cdf0e10cSrcweir#
10*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
11*cdf0e10cSrcweir#
12*cdf0e10cSrcweir# This file is part of OpenOffice.org.
13*cdf0e10cSrcweir#
14*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
15*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
16*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
17*cdf0e10cSrcweir#
18*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
19*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
20*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
22*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
23*cdf0e10cSrcweir#
24*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
25*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
26*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
27*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
28*cdf0e10cSrcweir#
29*cdf0e10cSrcweir#*************************************************************************
30*cdf0e10cSrcweir#
31*cdf0e10cSrcweir# Create ordinary theme from HiContrast images.
32*cdf0e10cSrcweir#
33*cdf0e10cSrcweir
34*cdf0e10cSrcweiruse File::Copy;
35*cdf0e10cSrcweiruse File::Find;
36*cdf0e10cSrcweiruse File::Path;
37*cdf0e10cSrcweiruse File::Spec;
38*cdf0e10cSrcweir
39*cdf0e10cSrcweir( $src, $dst ) = @ARGV;
40*cdf0e10cSrcweir
41*cdf0e10cSrcweirif ( $src eq "" || $dst eq "" ) {
42*cdf0e10cSrcweir    print STDERR "Usage: hicontrast-to-theme.pl src dest\n\n";
43*cdf0e10cSrcweir    print STDERR "Create ordinary theme from HiContrast images.\n";
44*cdf0e10cSrcweir    exit 1;
45*cdf0e10cSrcweir}
46*cdf0e10cSrcweir
47*cdf0e10cSrcweir$dst = File::Spec->rel2abs( $dst );
48*cdf0e10cSrcweir
49*cdf0e10cSrcweir@hc_table = (
50*cdf0e10cSrcweir    [ ".*_h.png",         "_h.png",    ".png" ],
51*cdf0e10cSrcweir    [ ".*_sch.png",       "_sch.png",  ".png" ],
52*cdf0e10cSrcweir    [ ".*_hc.png",        "_hc.png",   ".png" ],
53*cdf0e10cSrcweir    [ "lch_.*.png",       "lch_",      "lc_" ],
54*cdf0e10cSrcweir    [ "sch_.*.png",       "sch_",      "sc_" ],
55*cdf0e10cSrcweir    [ "lch[0-9].*.png",   "lch",       "lc" ],
56*cdf0e10cSrcweir    [ "sch[0-9].*.png",   "sch",       "sc" ],
57*cdf0e10cSrcweir    [ "loh[0-9].*.png",   "loh",       "lo" ],
58*cdf0e10cSrcweir    [ "lxh[0-9].*.png",   "lxh",       "lx" ],
59*cdf0e10cSrcweir    [ "sxh[0-9].*.png",   "sxh",       "sx" ],
60*cdf0e10cSrcweir    [ "avh[0-9].*.png",   "avh",       "av" ],
61*cdf0e10cSrcweir    [ "avlh[0-9].*.png",  "avlh",      "avl" ],
62*cdf0e10cSrcweir    [ "idh[0-9].*.png",   "idh",       "id" ],
63*cdf0e10cSrcweir    [ "imh[0-9].*.png",   "imh",       "im" ],
64*cdf0e10cSrcweir    [ "mih[0-9].*.png",   "mih",       "mi" ],
65*cdf0e10cSrcweir    [ "tbh[0-9].*.png",   "tbh",       "tb" ],
66*cdf0e10cSrcweir    [ "nah[0-9].*.png",   "nah",       "na" ],
67*cdf0e10cSrcweir    [ "nch[0-9].*.png",   "nch",       "nc" ],
68*cdf0e10cSrcweir    [ "nvh[0-9].*.png",   "nvh",       "nv" ],
69*cdf0e10cSrcweir    [ "ouh[0-9].*.png",   "ouh",       "ou" ],
70*cdf0e10cSrcweir    [ "ddh[0-9].*.png",   "ddh",       "dd" ],
71*cdf0e10cSrcweir    [ "sfh[0-9].*.png",   "sfh",       "sf" ],
72*cdf0e10cSrcweir    [ "srh[0-9].*.png",   "srh",       "sr" ],
73*cdf0e10cSrcweir    [ "wrh[0-9].*.png",   "wrh",       "wr" ],
74*cdf0e10cSrcweir    [ "alh[0-9].*.png",   "alh",       "al" ],
75*cdf0e10cSrcweir    [ "ath[0-9].*.png",   "ath",       "at" ],
76*cdf0e10cSrcweir    [ "bih[0-9].*.png",   "bih",       "bi" ],
77*cdf0e10cSrcweir    [ "coh[0-9].*.png",   "coh",       "co" ],
78*cdf0e10cSrcweir    [ "foh[0-9].*.png",   "foh",       "fo" ],
79*cdf0e10cSrcweir    [ "fuh[0-9].*.png",   "fuh",       "fu" ],
80*cdf0e10cSrcweir    [ "oph[0-9].*.png",   "oph",       "op" ],
81*cdf0e10cSrcweir    [ "unh[0-9].*.png",   "unh",       "un" ],
82*cdf0e10cSrcweir    [ "edh[0-9].*.png",   "edh",       "ed" ],
83*cdf0e10cSrcweir    [ "cdh[0-9].*.png",   "cdh",       "cd" ],
84*cdf0e10cSrcweir    [ "frh[0-9].*.png",   "frh",       "fr" ],
85*cdf0e10cSrcweir    [ "fwh[0-9].*.png",   "fwh",       "fw" ],
86*cdf0e10cSrcweir    [ "nuh[0-9].*.png",   "nuh",       "nu" ],
87*cdf0e10cSrcweir    [ "prh[0-9].*.png",   "prh",       "pr" ],
88*cdf0e10cSrcweir    [ "shh[0-9].*.png",   "shh",       "sh" ],
89*cdf0e10cSrcweir    [ "trh[0-9].*.png",   "trh",       "tr" ],
90*cdf0e10cSrcweir    [ "reh[0-9].*.png",   "reh",       "re" ],
91*cdf0e10cSrcweir    [ "joh[0-9].*.png",   "joh",       "jo" ],
92*cdf0e10cSrcweir    [ "fph[0-9].*.png",   "fph",       "fp" ],
93*cdf0e10cSrcweir    [ "dah[0-9].*.png",   "dah",       "da" ]
94*cdf0e10cSrcweir);
95*cdf0e10cSrcweir
96*cdf0e10cSrcweirmy (@from_stat, @to_stat);
97*cdf0e10cSrcweir
98*cdf0e10cSrcweirsub copy_normalized {
99*cdf0e10cSrcweir    $file = $_;
100*cdf0e10cSrcweir    for $hc ( @hc_table ) {
101*cdf0e10cSrcweir        ( $what, $from, $to ) = @$hc;
102*cdf0e10cSrcweir        if ( $file =~ /$what/&&!($file=~/\.svn/) ) {
103*cdf0e10cSrcweir            my $dir = File::Spec->catdir( $dst, $File::Find::dir );
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir            if ( ! -d $dir ) {
106*cdf0e10cSrcweir                mkpath( $dir );
107*cdf0e10cSrcweir            }
108*cdf0e10cSrcweir
109*cdf0e10cSrcweir            ( my $copy = $file ) =~ s/$from/$to/;
110*cdf0e10cSrcweir            $copy = File::Spec->catfile( $dir, $copy );
111*cdf0e10cSrcweir
112*cdf0e10cSrcweir	        @from_stat = stat($file);
113*cdf0e10cSrcweir	        @to_stat = stat($copy);
114*cdf0e10cSrcweir			if ( $from_stat[9] > $to_stat[9] ) {
115*cdf0e10cSrcweir	            copy( $file, $copy ) || die $!;
116*cdf0e10cSrcweir				utime( $from_stat[9], $from_stat[9], $copy );
117*cdf0e10cSrcweir			}
118*cdf0e10cSrcweir
119*cdf0e10cSrcweir            last;
120*cdf0e10cSrcweir        }
121*cdf0e10cSrcweir    }
122*cdf0e10cSrcweir}
123*cdf0e10cSrcweir
124*cdf0e10cSrcweirchdir( $src );
125*cdf0e10cSrcweirfind( \&copy_normalized, '.' );
126