This repository was archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcheck_for_bad_includes.pl
executable file
·81 lines (72 loc) · 2.65 KB
/
check_for_bad_includes.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl -w
#
# Script to replace all incorrect "include" statements in WRF trunk. For user-defined files,
# include statements must use quotes, not brackets, according to the C standard:
#
# INCORRECT
# #include <model_data_order.inc>
#
# CORRECT
# #include "model_data_order.inc"
# OPTIONS:
# use "--search_path" to specify the search pattern for files you want to edit.
# - Separate different search patterns with spaces
# - Be sure to escape wildcard characters with a backslash!
# - Default is --search_path="../\*/\*.F ../\*/\*/\*.F ../\*/\*/\*/\*.F ../\*/\*/\*/\*/\*.F ../\*/\*.inc ../\*/\*/\*.f90 ../\*/\*/\*/\*.f90"
# use "--dryrun=yes" to do a dry run, where all the output of what would be changed is printed out, but no changes are made.
#
# Created by Michael Kavulich, November 2015
# No rights reserved
#
use strict;
use warnings;
use File::Basename;
use Getopt::Long;
my $dryrun = "no";
my $search_path = "../\*/\*.F ../\*/\*/\*.F ../\*/\*/\*/\*.F ../\*/\*/\*/\*/\*.F ../\*/\*.inc ../\*/\*/\*.f90 ../\*/\*/\*/\*.f90";
GetOptions ('search_path=s' => \$search_path,
"dryrun:s" => \$dryrun ) or die "\nInvalid option(s) specified, view script comments for help\n";
print "\nSearching for brackets in file(s): $search_path\n\n";
my @source_files=glob("$search_path");
my $found=0;
my $notfound=0;
my $changed=0;
foreach my $filename (@source_files) {
open (IN, $filename) or die "Cannot open file $filename for read: $!";
my @lines=<IN>;
close IN;
if (grep(/#(\s*)(include|INCLUDE)(\s*)</,@lines)) {
print "Brackets found in file: $filename\n";
$found ++;
} else {
# print "Brackets NOT found in file: $filename\n";
$notfound ++;
next;
}
open (OUT, ">", $filename) or die "Cannot open file $filename for write: $!";
foreach my $line (@lines) {
if ($line =~ /#(\s*)(include|INCLUDE)(\s*)</) {
print "Found line with brackets: $line\n";
my @inc_files = split /[<>]/,$line;
if ($inc_files[1] =~ /<mpi.*/) {
print "Skipping line that contains 'mpi':\n";
print "$line\n";
} else {
if ( $dryrun =~ /y/i ) {
my $linetemp = $line;
$linetemp =~ s/<$inc_files[1]>/\"$inc_files[1]\"/;
print "Changed line to: $linetemp\n";
} else {
$line =~ s/<$inc_files[1]>/\"$inc_files[1]\"/;
print "Changed line to: $line\n";
}
$changed++;
}
}
print OUT $line;
}
close OUT;
}
print "\nBrackets found in $found files.\n";
print "\nBrackets NOT found in $notfound files.\n";
print "\n$changed lines changed\n";