xref: /trunk/main/postprocess/checkxml/checkxml.pl (revision 7e90fac2)
1cdf0e10cSrcweir:
2cdf0e10cSrcweireval 'exec perl -wS $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#
28cdf0e10cSrcweir# check_xml.pl - check xml,xcs,xcu files size, NULL character
29cdf0e10cSrcweir#
30cdf0e10cSrcweir
31cdf0e10cSrcweirmy
32cdf0e10cSrcweir$is_debug=0;
33cdf0e10cSrcweirmy $err = 0;
34cdf0e10cSrcweirmy $path = $ENV{'SOLARVERSION'} . '/' . $ENV{'INPATH'} . '/xml' . "$ENV{'UPDMINOREXT'}/";
35cdf0e10cSrcweirmy $pck_path = $ENV{'SOLARVERSION'} . '/' . $ENV{'INPATH'} . '/pck' . "$ENV{'UPDMINOREXT'}/";
36cdf0e10cSrcweirmy $unzipexe="unzip";
37cdf0e10cSrcweir
38cdf0e10cSrcweir#Path of the directory from which the recursion starts (must have ending '/').
39cdf0e10cSrcweirprint "Checking:$path\n";
40cdf0e10cSrcweir# Initiate the recursion
41cdf0e10cSrcweir&RecurseDirs($path);
42cdf0e10cSrcweir$err += &check_registry_zips($pck_path);
43cdf0e10cSrcweirif ($err > 0)
44cdf0e10cSrcweir{
45cdf0e10cSrcweir    print "Error: $err damaged files encountered\n";
46cdf0e10cSrcweir    exit(1); # stop dmake
47cdf0e10cSrcweir} else
48cdf0e10cSrcweir{
49cdf0e10cSrcweir    print "ok.\n";
50cdf0e10cSrcweir}
51cdf0e10cSrcweirexit;
52cdf0e10cSrcweir
53cdf0e10cSrcweir#### SUBROUTINES SECTION ####
54cdf0e10cSrcweir
55cdf0e10cSrcweir# Function that recurses through the directory tree calling FileFunction on all files
56cdf0e10cSrcweirsub RecurseDirs {
57cdf0e10cSrcweir    my ($path) = @_;
58cdf0e10cSrcweir    my $file;    #Variable for a file
59cdf0e10cSrcweir
60cdf0e10cSrcweir    opendir (DIRECTORY, $path) or
61cdf0e10cSrcweir        die "Can't read $path\n";
62cdf0e10cSrcweir    my @all_files = grep (!/^\.\.?$/, readdir (DIRECTORY)); #Read all the files except for '.' and '..'
63cdf0e10cSrcweir    closedir (DIRECTORY);
64cdf0e10cSrcweir
65cdf0e10cSrcweir    foreach $file (@all_files) {
66cdf0e10cSrcweir        if (-d "$path$file/") {
67cdf0e10cSrcweir            &RecurseDirs("$path$file/");
68cdf0e10cSrcweir        } else {
69cdf0e10cSrcweir            &check($path, $file);
70cdf0e10cSrcweir        }
71cdf0e10cSrcweir    }
72cdf0e10cSrcweir}
73cdf0e10cSrcweir
74cdf0e10cSrcweir############################################################################
75cdf0e10cSrcweirsub check       #04.02.2005 13:40
76cdf0e10cSrcweir############################################################################
77cdf0e10cSrcweir {
78cdf0e10cSrcweir    my $path = shift;
79cdf0e10cSrcweir    my $file = shift;
80cdf0e10cSrcweir    print "$path$file\n" if ((-e "$path$file") && $is_debug);
81cdf0e10cSrcweir    return if ( $file !~ /.+\.(xcu|xml|xcs)/ ); #check xml and xcu files only
82cdf0e10cSrcweir    if ( -z "$path$file" ) {
83cdf0e10cSrcweir        print "Error: $path$file 0 Bytes!\n";
84cdf0e10cSrcweir        $err++;
85cdf0e10cSrcweir    } else
86cdf0e10cSrcweir    {
87cdf0e10cSrcweir        open( FH, "<$path$file" );
88cdf0e10cSrcweir        while ( $line = <FH> ) {
89cdf0e10cSrcweir        #print $line;
90cdf0e10cSrcweir            if ( $line =~ /\000+/ ) {
91cdf0e10cSrcweir                print "Error: NULL characters detected in $path$file\n";
92cdf0e10cSrcweir                $err++;
93cdf0e10cSrcweir            }
94cdf0e10cSrcweir        }
95cdf0e10cSrcweir        close(FH);
96cdf0e10cSrcweir    }
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir ############################################################################
100cdf0e10cSrcweir sub check_registry_zips        #20.04.2005 18:47
101cdf0e10cSrcweir ############################################################################
102cdf0e10cSrcweir  {
103cdf0e10cSrcweir    my $path = shift;
104cdf0e10cSrcweir    my $error = 0;
105cdf0e10cSrcweir    my $commandargs;
106cdf0e10cSrcweir    opendir (DIRECTORY, $path) or
107cdf0e10cSrcweir        die "Can't read $path\n";
108cdf0e10cSrcweir    my @all_files = grep (!/^\.\.?$/, readdir (DIRECTORY)); #Read all the files except for '.' and '..'
109cdf0e10cSrcweir    closedir (DIRECTORY);
110cdf0e10cSrcweir    foreach $file (@all_files) {
111cdf0e10cSrcweir        if ( $file =~ /registry_.+\.zip$/ ) {
112cdf0e10cSrcweir            $commandargs="$path$file";
113cdf0e10cSrcweir            # Cygwin's perl needs escaped \ in system() and open( COMMAND ... )
114cdf0e10cSrcweir            if ( "$^O" eq "cygwin" ) { $commandargs =~ s/\\/\\\\/g; }
115cdf0e10cSrcweir            print "file=$commandargs\n" if ($is_debug);
116cdf0e10cSrcweir            open(UNZIP,"$unzipexe -l $commandargs |");
117cdf0e10cSrcweir            my $ferror = 0;
118cdf0e10cSrcweir            while ( $line = <UNZIP> ) {
119cdf0e10cSrcweir                #print $line;
120cdf0e10cSrcweir                my @param = split(" ",$line);
121cdf0e10cSrcweir                if ( $param[0] =~ /\d+/ ) {
122cdf0e10cSrcweir                    if ( $param[0] == 0 && $param[3] =~ /.+\.xcu$/)
123cdf0e10cSrcweir                    {
124cdf0e10cSrcweir                        $error++; $ferror=1;
125cdf0e10cSrcweir                    }
126cdf0e10cSrcweir                }
127cdf0e10cSrcweir            }
128cdf0e10cSrcweir            if ( $ferror ) {
129cdf0e10cSrcweir                print "Error: $commandargs contains files with 0 byte size\n";
130cdf0e10cSrcweir            }
131cdf0e10cSrcweir            close(UNZIP);
132cdf0e10cSrcweir        }
133cdf0e10cSrcweir    }
134cdf0e10cSrcweir
135cdf0e10cSrcweir    ($error);
136cdf0e10cSrcweir }  ##check_registry_zips
137