1:
2eval 'exec perl -wS $0 ${1+"$@"}'
3    if 0;
4#**************************************************************
5#
6#  Licensed to the Apache Software Foundation (ASF) under one
7#  or more contributor license agreements.  See the NOTICE file
8#  distributed with this work for additional information
9#  regarding copyright ownership.  The ASF licenses this file
10#  to you under the Apache License, Version 2.0 (the
11#  "License"); you may not use this file except in compliance
12#  with the License.  You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16#  Unless required by applicable law or agreed to in writing,
17#  software distributed under the License is distributed on an
18#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19#  KIND, either express or implied.  See the License for the
20#  specific language governing permissions and limitations
21#  under the License.
22#
23#**************************************************************
24
25
26#
27#
28# check_xml.pl - check xml,xcs,xcu files size, NULL character
29#
30
31my
32$is_debug=0;
33my $err = 0;
34my $path = $ENV{'SOLARVERSION'} . '/' . $ENV{'INPATH'} . '/xml' . "$ENV{'UPDMINOREXT'}/";
35my $pck_path = $ENV{'SOLARVERSION'} . '/' . $ENV{'INPATH'} . '/pck' . "$ENV{'UPDMINOREXT'}/";
36my $unzipexe="unzip";
37
38#Path of the directory from which the recursion starts (must have ending '/').
39print "Checking:$path\n";
40# Initiate the recursion
41&RecurseDirs($path);
42$err += &check_registry_zips($pck_path);
43if ($err > 0)
44{
45    print "Error: $err damaged files encountered\n";
46    exit(1); # stop dmake
47} else
48{
49    print "ok.\n";
50}
51exit;
52
53#### SUBROUTINES SECTION ####
54
55# Function that recurses through the directory tree calling FileFunction on all files
56sub RecurseDirs {
57    my ($path) = @_;
58    my $file;    #Variable for a file
59
60    opendir (DIRECTORY, $path) or
61        die "Can't read $path\n";
62    my @all_files = grep (!/^\.\.?$/, readdir (DIRECTORY)); #Read all the files except for '.' and '..'
63    closedir (DIRECTORY);
64
65    foreach $file (@all_files) {
66        if (-d "$path$file/") {
67            &RecurseDirs("$path$file/");
68        } else {
69            &check($path, $file);
70        }
71    }
72}
73
74############################################################################
75sub check       #04.02.2005 13:40
76############################################################################
77 {
78    my $path = shift;
79    my $file = shift;
80    print "$path$file\n" if ((-e "$path$file") && $is_debug);
81    return if ( $file !~ /.+\.(xcu|xml|xcs)/ ); #check xml and xcu files only
82    if ( -z "$path$file" ) {
83        print "Error: $path$file 0 Bytes!\n";
84        $err++;
85    } else
86    {
87        open( FH, "<$path$file" );
88        while ( $line = <FH> ) {
89        #print $line;
90            if ( $line =~ /\000+/ ) {
91                print "Error: NULL characters detected in $path$file\n";
92                $err++;
93            }
94        }
95        close(FH);
96    }
97 }
98
99 ############################################################################
100 sub check_registry_zips        #20.04.2005 18:47
101 ############################################################################
102  {
103    my $path = shift;
104    my $error = 0;
105    my $commandargs;
106    opendir (DIRECTORY, $path) or
107        die "Can't read $path\n";
108    my @all_files = grep (!/^\.\.?$/, readdir (DIRECTORY)); #Read all the files except for '.' and '..'
109    closedir (DIRECTORY);
110    foreach $file (@all_files) {
111        if ( $file =~ /registry_.+\.zip$/ ) {
112            $commandargs="$path$file";
113            # Cygwin's perl needs escaped \ in system() and open( COMMAND ... )
114            if ( "$^O" eq "cygwin" ) { $commandargs =~ s/\\/\\\\/g; }
115            print "file=$commandargs\n" if ($is_debug);
116            open(UNZIP,"$unzipexe -l $commandargs |");
117            my $ferror = 0;
118            while ( $line = <UNZIP> ) {
119                #print $line;
120                my @param = split(" ",$line);
121                if ( $param[0] =~ /\d+/ ) {
122                    if ( $param[0] == 0 && $param[3] =~ /.+\.xcu$/)
123                    {
124                        $error++; $ferror=1;
125                    }
126                }
127            }
128            if ( $ferror ) {
129                print "Error: $commandargs contains files with 0 byte size\n";
130            }
131            close(UNZIP);
132        }
133    }
134
135    ($error);
136 }  ##check_registry_zips
137