2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # fix-includes, a simple script replace local includes which should be global
10 # , to global includes. And global includes which should be local, to local includes.
11 # The script is expected to run in the root of the git repo, so it can fetch all the include directory's.
19 my $dirname = "include";
21 # Fetch the list of includes
22 my @subdirs = map {basename
$_} grep {-d
} glob("$dirname/*");
25 push(@subdirs,"boost");
27 # Simple function to check and replace headers
30 my ($dir,$file, @includes) = @_;
31 open(my $fh,"+<",$file) or die "Couldn't open file $file $!\n";
35 # seek to the first line, so we can replace then lines correctly
37 foreach $line (@content){
38 if($line =~ m/#include "(\w*)\//){
39 # If a include is local and it should be global, make it global
41 print "local header $line\n";
45 print "converted to global header $line\n";
51 # If a local file is defined global, make it local
52 elsif($line =~ /#include <((\w*)\.(hxx|h|hrc|src))>/){
53 # check if file exists, then it must be local so replace the <> to ""
55 print "global header $line\n";
59 print "converted to local header $line\n";
72 # routine that checks the headers of every cxx,hxx,c,h,hrc,src file in a directory
76 opendir(my $fh, $dir) or die "Program stopping, could't open directory \n";
77 while(my $file = readdir($fh)){
78 if($file =~ m/\.(cxx|hxx|c|h|hrc|src)$/i ){
79 check_headers
($dir,"$dir/$file",@subdirs);
85 # Expect ARGV[0] to be a directory, then fetch all subdirectory's and check the header files.
87 my @directories = io
->dir($ARGV[0])->All_Dirs;
88 foreach my $dir (@directories){
89 print "checking header files in $dir\n";
94 print "$ARGV[0] isn't a directory\n";