| 1 | #!/usr/bin/perl | 
|---|
| 2 |  | 
|---|
| 3 | use strict; | 
|---|
| 4 | use warnings; | 
|---|
| 5 |  | 
|---|
| 6 | my $debug_matching = 0; # set to 1 to view file matching and decision | 
|---|
| 7 | my $ignore_unknown = 0; | 
|---|
| 8 |  | 
|---|
| 9 | # ------------------------------------------------------------ | 
|---|
| 10 | # override checks below and save strictly as checked-in in SVN | 
|---|
| 11 |  | 
|---|
| 12 | my @strictly_as_in_svn_when_matchesDir = ( | 
|---|
| 13 | qr/\/GDE\/MAFFT\/mafft-[0-9\.]+-with[out]*-extensions/o, | 
|---|
| 14 | ); | 
|---|
| 15 |  | 
|---|
| 16 | # ------------------------------------------------------------ | 
|---|
| 17 | # skipped_directories and files inside are never examined: | 
|---|
| 18 |  | 
|---|
| 19 | my @skipped_directories = ( | 
|---|
| 20 | qr/\/.+\/bin$/o, | 
|---|
| 21 | qr/\/.+\/build$/o, | 
|---|
| 22 | qr/\/bin\/sativa$/o, | 
|---|
| 23 | qr/\/HELP_SOURCE\/Xml$/o, | 
|---|
| 24 | qr/\/GDE\/MUSCLE\/obj$/o, | 
|---|
| 25 | qr/\/GDE\/PHYML20130708\/phyml\/autom4te.cache$/o, | 
|---|
| 26 | qr/\/GDE\/RAxML8\/builddir/o, | 
|---|
| 27 | qr/\/GDE\/SATIVA\/builddir/o, | 
|---|
| 28 | qr/\/ignore\./o, | 
|---|
| 29 | qr/\/PERL2ARB\/blib$/o, | 
|---|
| 30 | qr/\/HEADERLIBS\/[^\/]+/o, | 
|---|
| 31 | qr/\/UNIT_TESTER\/logs$/o, | 
|---|
| 32 | qr/\/UNIT_TESTER\/tests$/o, | 
|---|
| 33 | qr/\/UNIT_TESTER\/tests\.slow$/o, | 
|---|
| 34 | qr/\/UNIT_TESTER\/run\/homefake\/.arb_prop\/(macros|cfgSave)$/o, | 
|---|
| 35 | qr/^\.\/ARB_SOURCE_DOC/o, | 
|---|
| 36 | qr/^\.\/dep_graphs/o, | 
|---|
| 37 | qr/^\.\/INCLUDE$/o, | 
|---|
| 38 | qr/^\.\/lib\/help$/o, | 
|---|
| 39 | qr/^\.\/lib\/help_html$/o, | 
|---|
| 40 | qr/^\.\/lib\/pts$/o, | 
|---|
| 41 | qr/^\.\/lib\/mafft$/o, | 
|---|
| 42 | qr/^\.\/patches.arb$/o, | 
|---|
| 43 | qr/^\.\/PERL5$/o, | 
|---|
| 44 | qr/_COM\/DUMP$/o, | 
|---|
| 45 | qr/_COM\/GEN[CH]$/o, | 
|---|
| 46 | qr/_COM\/O$/o, | 
|---|
| 47 | qr/_GEN$/o, | 
|---|
| 48 | qr/nbproject/o, | 
|---|
| 49 | # needed by ralf: | 
|---|
| 50 | qr/^\.\/test_arb_make_targets_logs/o, | 
|---|
| 51 | qr/\.dSYM$/o, | 
|---|
| 52 | ); | 
|---|
| 53 |  | 
|---|
| 54 | # first used/skipped match wins (exception see @3 below) | 
|---|
| 55 |  | 
|---|
| 56 | my %used_files = map { $_ => 1; } ( | 
|---|
| 57 | '!BRANCH_STATE', | 
|---|
| 58 | 'AUTHORS', | 
|---|
| 59 | 'COPYING', | 
|---|
| 60 | 'demo.arb', | 
|---|
| 61 | 'Doxyfile', | 
|---|
| 62 | 'export2sub', | 
|---|
| 63 | 'Makefile', | 
|---|
| 64 | 'Makefile.org', | 
|---|
| 65 | 'Makefile.setup.include', | 
|---|
| 66 | 'Makefile.setup.template', | 
|---|
| 67 | 'Makefile.suite', | 
|---|
| 68 | 'Makefile.test', | 
|---|
| 69 | 'needs_libs', | 
|---|
| 70 | ); | 
|---|
| 71 |  | 
|---|
| 72 | my %skipped_files = map { $_ => 1; } ( | 
|---|
| 73 | '.build.lst', | 
|---|
| 74 | '.cvsignore', | 
|---|
| 75 | '.depends', | 
|---|
| 76 | 'ChangeLog', | 
|---|
| 77 | 'config.makefile', | 
|---|
| 78 | 'helpfiles.lst', | 
|---|
| 79 | 'last.success', | 
|---|
| 80 | 'Makefile.setup.local', | 
|---|
| 81 | 'makeloc.here', | 
|---|
| 82 | 'makeloc.here', | 
|---|
| 83 | 'nt_date.h', | 
|---|
| 84 | 'postcompile.sav', | 
|---|
| 85 | 'TAGS', | 
|---|
| 86 | '.DS_Store', | 
|---|
| 87 | ); | 
|---|
| 88 |  | 
|---|
| 89 | my %used_extensions = map { $_ => 1; } ( # matches part behind last '.' in filename | 
|---|
| 90 | 'c', 'cpp', 'cxx', 'cc', | 
|---|
| 91 | 'h', 'hpp', 'hxx', | 
|---|
| 92 |  | 
|---|
| 93 | 'aisc', 'pa', | 
|---|
| 94 | 'bitmap', | 
|---|
| 95 | 'dtd', 'xsl', | 
|---|
| 96 | 'f', | 
|---|
| 97 | 'footer', | 
|---|
| 98 | 'head', 'header', | 
|---|
| 99 | 'i',  # swig input | 
|---|
| 100 | 'inc', | 
|---|
| 101 | 'java', 'manifest', | 
|---|
| 102 | 'makefile', | 
|---|
| 103 | 'pl', 'pm', 'PL', 'cgi', 'xs', | 
|---|
| 104 | 'awk', | 
|---|
| 105 | 'py', | 
|---|
| 106 | 'script', | 
|---|
| 107 | 'sh', | 
|---|
| 108 | 'source', 'menu', | 
|---|
| 109 | 'template', 'default', | 
|---|
| 110 | 'txt', 'doc', 'ps', 'pdf', | 
|---|
| 111 | 'tgz', 'gz', | 
|---|
| 112 | 'svg', 'png', | 
|---|
| 113 | ); | 
|---|
| 114 |  | 
|---|
| 115 | my %skipped_extensions = map { $_ => 1; } ( # matches part behind last '.' in filename | 
|---|
| 116 | 'a', | 
|---|
| 117 | 'bak', | 
|---|
| 118 | 'class', | 
|---|
| 119 | 'bundle', # Some file from XCode | 
|---|
| 120 | 'gcno', | 
|---|
| 121 | 'genmenu', | 
|---|
| 122 | 'jar', | 
|---|
| 123 | 'last_gcc', | 
|---|
| 124 | 'last_compiler', | 
|---|
| 125 | 'list', | 
|---|
| 126 | 'log', | 
|---|
| 127 | 'o', | 
|---|
| 128 | 'old', | 
|---|
| 129 | 'patch', | 
|---|
| 130 | 'rej', | 
|---|
| 131 | 'so', | 
|---|
| 132 | 'stamp', | 
|---|
| 133 | 'swp', | 
|---|
| 134 | 'yml', 'json', # perl2arb | 
|---|
| 135 | ); | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | # used_when_matches, skipped_when_matches and used_when_matchesFull are only tested, | 
|---|
| 139 | # if above filters did not match: | 
|---|
| 140 |  | 
|---|
| 141 | my @used_when_matches = ( | 
|---|
| 142 | qr/^arb_.*\.txt$/o, | 
|---|
| 143 | qr/disclaimer/io, | 
|---|
| 144 | qr/license/io, | 
|---|
| 145 | qr/needs_libs\..*/io, | 
|---|
| 146 | qr/readme$/io, | 
|---|
| 147 | qr/typemap$/io, | 
|---|
| 148 | ); | 
|---|
| 149 |  | 
|---|
| 150 | my @skipped_when_matches = ( | 
|---|
| 151 | qr/.*~$/o, # backups | 
|---|
| 152 | qr/\#.*\#$/o, | 
|---|
| 153 | qr/\.\#.*$/o, | 
|---|
| 154 | qr/^arbsrc.*\.tgz$/o, | 
|---|
| 155 | qr/^arbsrc\.lst$/o, | 
|---|
| 156 | qr/^arbsrc\.lst\.tmp$/o, | 
|---|
| 157 | qr/^callgrind\./o, | 
|---|
| 158 | ); | 
|---|
| 159 |  | 
|---|
| 160 | my @used_when_matchesFull = ( | 
|---|
| 161 | qr/\/AISC_COM\/AISC\/magic.lst$/o, | 
|---|
| 162 | qr/\/CLUSTALW\/.*$/o, | 
|---|
| 163 | qr/\/EISPACK\/rg\.html$/o, | 
|---|
| 164 | qr/\/GDE\/.*\.html$/o, | 
|---|
| 165 | qr/\/GDEHELP\/FASTA/o, | 
|---|
| 166 | qr/\/GDEHELP\/GDE.*/o, | 
|---|
| 167 | qr/\/GDEHELP\/HELP_PLAIN/o, | 
|---|
| 168 | qr/\/GDEHELP\/HELP_WRITTEN/o, | 
|---|
| 169 | qr/\/GDEHELP\/Makefile\.helpfiles/o, | 
|---|
| 170 | qr/\/HEADERLIBS\/.*COPYING$/o, | 
|---|
| 171 | qr/\/HELP_SOURCE\/.*\.gif$/o, | 
|---|
| 172 | qr/\/HELP_SOURCE\/oldhelp\/.*\.(ps|pdf)\.gz$/o, | 
|---|
| 173 | qr/\/HELP_SOURCE\/oldhelp\/.*\.hlp$/o, | 
|---|
| 174 | qr/\/HGL_SRC\/plot\.icon$/o, | 
|---|
| 175 | qr/\/PERL2ARB\/.*\.html$/o, | 
|---|
| 176 | qr/\/PERL2ARB\/Makefile.main$/o, | 
|---|
| 177 | qr/\/PHYLIP\/doc\//o, | 
|---|
| 178 | qr/\/PROBE_SERVER\/.*\.conf$/o, | 
|---|
| 179 | qr/\/READSEQ\/.*\.help$/o, | 
|---|
| 180 | qr/\/READSEQ\/Formats$/o, | 
|---|
| 181 | qr/\/SH\/[^\/\.]*$/o, | 
|---|
| 182 | qr/\/SOURCE_TOOLS\//o, | 
|---|
| 183 | qr/\/TREEPUZZLE\/.*\.gif$/o, | 
|---|
| 184 | qr/\/UNIT_TESTER\/run\/.*\.a00$/o, | 
|---|
| 185 | qr/\/UNIT_TESTER\/run\/.*\.arb$/o, | 
|---|
| 186 | qr/\/UNIT_TESTER\/run\/.*\.amc$/o, | 
|---|
| 187 | qr/\/UNIT_TESTER\/run\/.*\.expected$/o, | 
|---|
| 188 | qr/\/UNIT_TESTER\/run\/.*\.fig$/o, | 
|---|
| 189 | qr/\/UNIT_TESTER\/run\/.*\.in$/o, | 
|---|
| 190 | qr/\/UNIT_TESTER\/run\/.*\.inp$/o, | 
|---|
| 191 | qr/\/UNIT_TESTER\/run\/.*\.input$/o, | 
|---|
| 192 | qr/\/UNIT_TESTER\/run\/.*\.out$/o, | 
|---|
| 193 | qr/\/UNIT_TESTER\/run\/.*\.tree$/o, | 
|---|
| 194 | qr/\/UNIT_TESTER\/run\/help\//o, | 
|---|
| 195 | qr/\/UNIT_TESTER\/run\/impexp\/.*\.exported$/o, | 
|---|
| 196 | qr/\/UNIT_TESTER\/valgrind\/arb_valgrind_logged$/o, | 
|---|
| 197 | qr/^\.\/etc\//o, | 
|---|
| 198 | qr/^\.\/lib\/arb_default\/.*\.arb$/o, | 
|---|
| 199 | qr/^\.\/lib\/arb_tcp_org\.dat$/o, | 
|---|
| 200 | qr/^\.\/lib\/config\.[^\.]+$/io, | 
|---|
| 201 | qr/^\.\/lib\/desktop\/.*$/o, | 
|---|
| 202 | qr/^\.\/lib\/export\/.*\.eft$/o, | 
|---|
| 203 | qr/^\.\/lib\/import\/.*\.ift2?$/o, | 
|---|
| 204 | qr/^\.\/lib\/inputMasks\/.*\.mask$/o, | 
|---|
| 205 | qr/^\.\/lib\/macros\/.*\.amc$/o, | 
|---|
| 206 | qr/^\.\/lib\/macros\/.checks\/.*\.expected$/o, | 
|---|
| 207 | qr/^\.\/lib\/nas\/names\.dat\.template$/o, | 
|---|
| 208 | qr/^\.\/lib\/pictures\/.*\.(fig|vfont)$/o, | 
|---|
| 209 | qr/^\.\/lib\/pixmaps\/.*\.xpm$/o, | 
|---|
| 210 | qr/^\.\/lib\/protein_2nd_structure\/.*\.dat$/o, | 
|---|
| 211 | qr/^\.\/lib\/rna3d\/.*\.(pdb|data)$/o, | 
|---|
| 212 | qr/^\.\/lib\/rna3d\/images\/.*\.png$/o, | 
|---|
| 213 | qr/^\.\/lib\/sellists\/.*\.sellst$/o, | 
|---|
| 214 | qr/^\.\/lib\/submit\//o, | 
|---|
| 215 | qr/^\.\/lib\/BUGS\//o, | 
|---|
| 216 | qr/^\.\/util\/arb_.*$/o, | 
|---|
| 217 | qr/^\.\/util\/config\..*$/o, | 
|---|
| 218 | qr/\/GDE\/.*\/Makefile\.[^\/]+$/io, | 
|---|
| 219 | qr/\/GDE\/PHYML[^\/]+\/phyml\//o, | 
|---|
| 220 | qr/\/GDE\/SATIVA\/sativa\//o, | 
|---|
| 221 | ); | 
|---|
| 222 |  | 
|---|
| 223 | # skipped_when_matchesFull and forced_when_matchesFull are always tested! (@3) | 
|---|
| 224 |  | 
|---|
| 225 | my @skipped_when_matchesFull = ( | 
|---|
| 226 | qr/\/genhelp\/.*\.hlp$/o, | 
|---|
| 227 | qr/\/lib\/addlibs\/(lib.*\.so\..*)$/o, | 
|---|
| 228 | qr/^\.\/arb.*\.tgz$/o, | 
|---|
| 229 | qr/^\.\/bin\//o, | 
|---|
| 230 | qr/^\.\/GDE\/CORE\/functions.h$/o, | 
|---|
| 231 | qr/^\.\/GDE\/PHYML[^\/]+\/phyml\/(configure|config.h.in)$/o, | 
|---|
| 232 | qr/^\.\/lib\/ARB\.pm$/o, | 
|---|
| 233 | qr/^\.\/lib\/arb_tcp\.dat$/o, | 
|---|
| 234 | qr/^\.\/lib\/gde\/.*\.menu$/o, | 
|---|
| 235 | qr/^\.\/lib\/nas\/names.*\.dat$/o, | 
|---|
| 236 | qr/^\.\/lib\/macros\/\.checks\/.*\.ids$/o, | 
|---|
| 237 | qr/^\.\/lib\/motifHack\/pixmaps\/.*$/o, | 
|---|
| 238 | qr/^\.\/PERL2ARB\/.*\.h$/o, | 
|---|
| 239 | qr/^\.\/PERL2ARB\/ARB\.bs$/o, | 
|---|
| 240 | qr/^\.\/PERL2ARB\/ARB\.c$/o, | 
|---|
| 241 | qr/^\.\/PERL2ARB\/ARB\.xs$/o, | 
|---|
| 242 | qr/^\.\/PERL2ARB\/Makefile$/o, | 
|---|
| 243 | qr/^\.\/PERL2ARB\/Makefile.PL$/o, | 
|---|
| 244 | qr/^\.\/PERL2ARB\/perlmain.c$/o, | 
|---|
| 245 | qr/^\.\/PERL2ARB\/pm_to_blib$/o, | 
|---|
| 246 | qr/^\.\/SOURCE_TOOLS\/valgrind2grep\.lst$/o, | 
|---|
| 247 | qr/^\.\/SOURCE_TOOLS\/stamp\./o, | 
|---|
| 248 | qr/^\.\/TEMPLATES\/arb_build\.h$/o, | 
|---|
| 249 | qr/^\.\/UNIT_TESTER\/run\/TEST_g?pt\.arb$/o, | 
|---|
| 250 | qr/^\.\/UNIT_TESTER\/run\/.*\.ARM$/o, | 
|---|
| 251 | qr/^\.\/UNIT_TESTER\/run\/.*\.ARF$/o, | 
|---|
| 252 | qr/^\.\/UNIT_TESTER\/Makefile\.setup\.local\.last$/o, | 
|---|
| 253 | qr/^\.\/TAGS\./o, # avoid failure while 'make tags' is running | 
|---|
| 254 | qr/date\.xsl$/o, | 
|---|
| 255 | ); | 
|---|
| 256 |  | 
|---|
| 257 | my @forced_when_matchesFull = ( | 
|---|
| 258 | qr/^\.\/bin\/Makefile/o, | 
|---|
| 259 | qr/\/PROBE_WEB\/SERVER\/.*\.jar$/o, | 
|---|
| 260 | qr/\/GDE\/PHYML[^\/]+\/phyml\/.*\.log$/o, | 
|---|
| 261 | qr/\/UNIT_TESTER\/run\/.*\.list$/o, | 
|---|
| 262 | ); | 
|---|
| 263 |  | 
|---|
| 264 | # files that are even packed when generated and not in VC | 
|---|
| 265 | my @pack_fullGenerated = ( | 
|---|
| 266 | qr/\/TEMPLATES\/svn_revision\.h$/o, | 
|---|
| 267 | ); | 
|---|
| 268 |  | 
|---|
| 269 | # ------------------------------------------------------------ | 
|---|
| 270 | # sanity checks | 
|---|
| 271 |  | 
|---|
| 272 | foreach (keys %used_extensions) { | 
|---|
| 273 | if (exists $skipped_extensions{$_}) { die "'$_' in \$used_extensions and \$skipped_extensions"; } | 
|---|
| 274 | } | 
|---|
| 275 | foreach (keys %used_files) { | 
|---|
| 276 | if (exists $skipped_files{$_}) { die "'$_' in \$used_files and \$skipped_files"; } | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | # ------------------------------------------------------------ | 
|---|
| 280 |  | 
|---|
| 281 | sub useDir($) { | 
|---|
| 282 | my ($dir) = @_; | 
|---|
| 283 |  | 
|---|
| 284 | if ($dir =~ /.svn$/o) { return 0; } | 
|---|
| 285 | if ($dir =~ /CVS$/o) { return 0; } | 
|---|
| 286 | foreach (@skipped_directories) { | 
|---|
| 287 | if ($dir =~ $_) { return 0; } | 
|---|
| 288 | } | 
|---|
| 289 | return 1; | 
|---|
| 290 | } | 
|---|
| 291 |  | 
|---|
| 292 | sub matchingExpr($\@) { | 
|---|
| 293 | # return 0 if no regexp matched, return index+1 otherwise | 
|---|
| 294 | my ($str,$regexp_arr_r) = @_; | 
|---|
| 295 |  | 
|---|
| 296 | my $regexps = scalar(@$regexp_arr_r); | 
|---|
| 297 | for (my $r=0; $r<$regexps; $r++) { | 
|---|
| 298 | my $reg = $$regexp_arr_r[$r]; | 
|---|
| 299 | if ($str =~ $reg) { | 
|---|
| 300 | return $r+1; | 
|---|
| 301 | } | 
|---|
| 302 | } | 
|---|
| 303 | return 0; | 
|---|
| 304 | } | 
|---|
| 305 |  | 
|---|
| 306 | sub useIfMatching($\@\$) { | 
|---|
| 307 | my ($str,$regexp_arr_r,$use_r) = @_; | 
|---|
| 308 | my $matches = matchingExpr($str,@$regexp_arr_r); | 
|---|
| 309 | if ($matches>0) { | 
|---|
| 310 | if ($debug_matching!=0) { print STDERR "'$str' matches '".$$regexp_arr_r[$matches-1]."' => use!\n"; } | 
|---|
| 311 | $$use_r = 1; | 
|---|
| 312 | } | 
|---|
| 313 | } | 
|---|
| 314 | sub dontUseIfMatching($\@\$) { | 
|---|
| 315 | my ($str,$regexp_arr_r,$use_r) = @_; | 
|---|
| 316 | my $matches = matchingExpr($str,@$regexp_arr_r); | 
|---|
| 317 | if ($matches>0) { | 
|---|
| 318 | if ($debug_matching!=0) { print STDERR "'$str' matches '".$$regexp_arr_r[$matches-1]."' => don't use!\n"; } | 
|---|
| 319 | $$use_r = 0; | 
|---|
| 320 | } | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | sub useFile($$) { | 
|---|
| 324 | my ($dir,$file) = @_; | 
|---|
| 325 |  | 
|---|
| 326 | my $use = undef; | 
|---|
| 327 | if (exists $used_files{$file}) { $use = 1; } | 
|---|
| 328 | elsif (exists $skipped_files{$file}) { $use = 0; } | 
|---|
| 329 |  | 
|---|
| 330 | my $hasExt = 0; | 
|---|
| 331 | if (not defined $use) { | 
|---|
| 332 | if ($file =~ /\.([^\.]+)$/o) { | 
|---|
| 333 | my $ext = $1; | 
|---|
| 334 | $hasExt = 1; | 
|---|
| 335 | if (exists $used_extensions{$ext}) { | 
|---|
| 336 | if ($debug_matching!=0) { print STDERR "'$file' matches extension '".$ext."' => use!\n"; } | 
|---|
| 337 | $use = 1; | 
|---|
| 338 | } | 
|---|
| 339 | elsif (exists $skipped_extensions{$ext}) { | 
|---|
| 340 | if ($debug_matching!=0) { print STDERR "'$file' matches extension '".$ext."' => don't use!\n"; } | 
|---|
| 341 | $use = 0; | 
|---|
| 342 | } | 
|---|
| 343 | } | 
|---|
| 344 | } | 
|---|
| 345 |  | 
|---|
| 346 | if (not defined $use) { | 
|---|
| 347 | useIfMatching($file,@used_when_matches, $use); | 
|---|
| 348 | } | 
|---|
| 349 |  | 
|---|
| 350 | if (not defined $use) { | 
|---|
| 351 | dontUseIfMatching($file,@skipped_when_matches, $use); | 
|---|
| 352 | } | 
|---|
| 353 |  | 
|---|
| 354 | my $full; | 
|---|
| 355 | if (not defined $use) { | 
|---|
| 356 | $full = $dir.'/'.$file; | 
|---|
| 357 |  | 
|---|
| 358 | useIfMatching($full,@used_when_matchesFull, $use); | 
|---|
| 359 | if (not defined $use) { | 
|---|
| 360 | if (-X $full and $hasExt==0) { $use = 0; } # exclude binaries by default (wrong for scripts) | 
|---|
| 361 | } | 
|---|
| 362 | } | 
|---|
| 363 |  | 
|---|
| 364 | if (not defined $use or $use==1) { | 
|---|
| 365 | if (not defined $full) { $full = $dir.'/'.$file; } | 
|---|
| 366 |  | 
|---|
| 367 | dontUseIfMatching($full,@skipped_when_matchesFull, $use); | 
|---|
| 368 | } | 
|---|
| 369 | if (not defined $use or $use==0) { | 
|---|
| 370 | if (not defined $full) { $full = $dir.'/'.$file; } | 
|---|
| 371 | useIfMatching($full,@forced_when_matchesFull, $use); | 
|---|
| 372 | } | 
|---|
| 373 |  | 
|---|
| 374 | if (not defined $use) { | 
|---|
| 375 | if ($ignore_unknown==0) { | 
|---|
| 376 | die "Don't know whether to use or skip '$file' (in $dir)"; | 
|---|
| 377 | } | 
|---|
| 378 | $use = 1; | 
|---|
| 379 | } | 
|---|
| 380 |  | 
|---|
| 381 | return $use; | 
|---|
| 382 | } | 
|---|
| 383 |  | 
|---|
| 384 | # ------------------------------------------------------------ | 
|---|
| 385 |  | 
|---|
| 386 | my $VC_FILE    = 1; | 
|---|
| 387 | my $VC_DIR     = 2; | 
|---|
| 388 | my $VC_UNKNOWN = 3; # in SVN, but unknown whether dir or file | 
|---|
| 389 |  | 
|---|
| 390 | my $svn_entries_read = 0; | 
|---|
| 391 | my %all_svn_entries = (); | 
|---|
| 392 |  | 
|---|
| 393 | sub isSVNcheckout($) { | 
|---|
| 394 | my ($dir) = @_; | 
|---|
| 395 | if (-f $dir.'/.svn/entries') { return 1; } | 
|---|
| 396 | if (-f $dir.'/.svn/wc.db') { return 1; } | 
|---|
| 397 | return 0; | 
|---|
| 398 | } | 
|---|
| 399 |  | 
|---|
| 400 | sub getSVNEntries($\%) { | 
|---|
| 401 | my ($dir,$SVN_r) = @_; | 
|---|
| 402 |  | 
|---|
| 403 | if ($svn_entries_read==0) { # first call | 
|---|
| 404 | if (isSVNcheckout($dir)==0) { return 0; } | 
|---|
| 405 |  | 
|---|
| 406 | my $cmd = "svn status -v $dir"; | 
|---|
| 407 | open(SVNSTATUS, "$cmd|") || die "failed to execute '$cmd' (Reason: $!)"; | 
|---|
| 408 |  | 
|---|
| 409 | eval { | 
|---|
| 410 | my $reg_status_line = qr/^(.*)\s+[0-9]+\s+[0-9]+\s+[^\s]+\s+([^\s]+)$/; | 
|---|
| 411 |  | 
|---|
| 412 | my $line; | 
|---|
| 413 | while (defined($line=<SVNSTATUS>)) { | 
|---|
| 414 | chomp($line); | 
|---|
| 415 | if ($line =~ $reg_status_line) { | 
|---|
| 416 | my ($flags,$name) = ($1,$2); | 
|---|
| 417 | if (-f $name) { | 
|---|
| 418 | $all_svn_entries{$name} = $VC_FILE; | 
|---|
| 419 | } | 
|---|
| 420 | elsif (-d $name) { | 
|---|
| 421 | $all_svn_entries{$name} = $VC_DIR; | 
|---|
| 422 | } | 
|---|
| 423 | else { | 
|---|
| 424 | $all_svn_entries{$name} = $VC_UNKNOWN; | 
|---|
| 425 | } | 
|---|
| 426 | } | 
|---|
| 427 | else { | 
|---|
| 428 | if ($line =~ /^?/) { | 
|---|
| 429 | ; # silently ignore unknown files | 
|---|
| 430 | } | 
|---|
| 431 | else { | 
|---|
| 432 | die "Cant parse line '$line'"; | 
|---|
| 433 | } | 
|---|
| 434 | } | 
|---|
| 435 | } | 
|---|
| 436 | }; | 
|---|
| 437 | if ($@) { | 
|---|
| 438 | die "Failed to read svn status: $@"; | 
|---|
| 439 | } | 
|---|
| 440 |  | 
|---|
| 441 | close(SVNSTATUS); | 
|---|
| 442 | $svn_entries_read = 1; | 
|---|
| 443 | } | 
|---|
| 444 |  | 
|---|
| 445 | if ($dir eq '.') { | 
|---|
| 446 | foreach (keys %all_svn_entries) { | 
|---|
| 447 | if (not /\//) { # root entry | 
|---|
| 448 | $$SVN_r{$_} = $all_svn_entries{$_}; | 
|---|
| 449 | } | 
|---|
| 450 | } | 
|---|
| 451 | } | 
|---|
| 452 | else { | 
|---|
| 453 | if (not $dir =~ /^\.\//) { die "expected '$dir' to start with './'"; } | 
|---|
| 454 | my $sdir = $'; | 
|---|
| 455 | my $reg_matchdir = qr/^$sdir\//; | 
|---|
| 456 | foreach (keys %all_svn_entries) { | 
|---|
| 457 | if ($_ =~ $reg_matchdir) { | 
|---|
| 458 | my $rest = $'; | 
|---|
| 459 | if (not $rest =~ /\//) { # in $dir (not below) | 
|---|
| 460 | $$SVN_r{$rest} = $all_svn_entries{$_}; | 
|---|
| 461 | } | 
|---|
| 462 | } | 
|---|
| 463 | } | 
|---|
| 464 | } | 
|---|
| 465 |  | 
|---|
| 466 | return 1; | 
|---|
| 467 | } | 
|---|
| 468 |  | 
|---|
| 469 | sub getCVSEntries($\%) { | 
|---|
| 470 | my ($dir,$CVS_r) = @_; | 
|---|
| 471 |  | 
|---|
| 472 | my $cvsentries = $dir.'/CVS/Entries'; | 
|---|
| 473 | if (-f $cvsentries) { | 
|---|
| 474 | open(CVS,'<'.$cvsentries) || die "can't read '$cvsentries' (Reason: $!)"; | 
|---|
| 475 | eval { | 
|---|
| 476 | foreach (<CVS>) { | 
|---|
| 477 | chomp; | 
|---|
| 478 | if (/^D\/([^\/]+)\//o) { # directory | 
|---|
| 479 | $$CVS_r{$1} = $VC_DIR; | 
|---|
| 480 | } | 
|---|
| 481 | elsif (/^\/([^\/]+)\//o) { # file | 
|---|
| 482 | $$CVS_r{$1} = $VC_FILE; | 
|---|
| 483 | } | 
|---|
| 484 | elsif (/^D$/o) { | 
|---|
| 485 | ; | 
|---|
| 486 | } | 
|---|
| 487 | else { | 
|---|
| 488 | die "can't parse line '$_'"; | 
|---|
| 489 | } | 
|---|
| 490 | } | 
|---|
| 491 | }; | 
|---|
| 492 | if ($@) { die "$@ while reading $cvsentries"; } | 
|---|
| 493 | close(CVS); | 
|---|
| 494 | return 1; | 
|---|
| 495 | } | 
|---|
| 496 | return 0; | 
|---|
| 497 | } | 
|---|
| 498 |  | 
|---|
| 499 | my $VC = '<no VC>'; | 
|---|
| 500 |  | 
|---|
| 501 | sub getVCEntries($\%) { | 
|---|
| 502 | my ($dir,$VC_r) = @_; | 
|---|
| 503 |  | 
|---|
| 504 | my $res = 1; | 
|---|
| 505 | if (getSVNEntries($dir,%$VC_r)==0) { | 
|---|
| 506 | if (getCVSEntries($dir,%$VC_r)==0) { | 
|---|
| 507 | $VC = '<no VC>'; | 
|---|
| 508 | $res = 0; | 
|---|
| 509 | } | 
|---|
| 510 | else { | 
|---|
| 511 | $VC = 'CVS'; | 
|---|
| 512 | } | 
|---|
| 513 | } | 
|---|
| 514 | else { | 
|---|
| 515 | $VC = 'SVN'; | 
|---|
| 516 | } | 
|---|
| 517 |  | 
|---|
| 518 | if (0) { | 
|---|
| 519 | print "$VC entries for $dir:\n"; | 
|---|
| 520 | foreach (sort keys %$VC_r) { | 
|---|
| 521 | print " ".$$VC_r{$_}.": $_\n"; | 
|---|
| 522 | } | 
|---|
| 523 | } | 
|---|
| 524 |  | 
|---|
| 525 | return $res; | 
|---|
| 526 | } | 
|---|
| 527 |  | 
|---|
| 528 | # ------------------------------------------------------------ | 
|---|
| 529 |  | 
|---|
| 530 | sub expectVCmember($$\%) { | 
|---|
| 531 | my ($full,$item,$VC_r) = @_; | 
|---|
| 532 | if ((not defined $$VC_r{$item}) and ($ignore_unknown==0)) { | 
|---|
| 533 | if (not matchingExpr($full,@pack_fullGenerated)) { | 
|---|
| 534 | die "'$full' ($_) included, but not in $VC (seems to be generated)"; | 
|---|
| 535 | } | 
|---|
| 536 | } | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 | my %unpackedCVSmember = map { $_ => 1; } ( | 
|---|
| 540 | '.cvsignore', | 
|---|
| 541 | 'ChangeLog', | 
|---|
| 542 | ); | 
|---|
| 543 |  | 
|---|
| 544 | sub unexpectVCmember($$\%) { | 
|---|
| 545 | my ($full,$item,$VC_r) = @_; | 
|---|
| 546 | if (defined $$VC_r{$item}) { | 
|---|
| 547 | if ((not exists $unpackedCVSmember{$item}) and ($ignore_unknown==0)) { | 
|---|
| 548 | die "'$full' excluded, but in $VC"; | 
|---|
| 549 | } | 
|---|
| 550 | } | 
|---|
| 551 | } | 
|---|
| 552 |  | 
|---|
| 553 | sub is_version_controlled($\%) { | 
|---|
| 554 | my ($item,$VC_r) = @_; | 
|---|
| 555 | if (defined $$VC_r{$item}) { | 
|---|
| 556 | return 1; | 
|---|
| 557 | } | 
|---|
| 558 | return 0; | 
|---|
| 559 | } | 
|---|
| 560 |  | 
|---|
| 561 | sub saveAsInSVNforDir($) { | 
|---|
| 562 | my ($dir) = @_; | 
|---|
| 563 | foreach my $reg (@strictly_as_in_svn_when_matchesDir) { | 
|---|
| 564 | if ($dir =~ $reg) { | 
|---|
| 565 | return 1; | 
|---|
| 566 | } | 
|---|
| 567 | } | 
|---|
| 568 | return 0; | 
|---|
| 569 | } | 
|---|
| 570 |  | 
|---|
| 571 | sub dumpFiles($); | 
|---|
| 572 | sub dumpFiles($) { | 
|---|
| 573 | my ($dir) = @_; | 
|---|
| 574 |  | 
|---|
| 575 | eval { | 
|---|
| 576 | my @subdirs; | 
|---|
| 577 | my @files; | 
|---|
| 578 |  | 
|---|
| 579 | my %CVS; | 
|---|
| 580 | if (!getVCEntries($dir,%CVS)) { | 
|---|
| 581 | die "arb_srclst.pl only works in a SVN checkout"; | 
|---|
| 582 | } | 
|---|
| 583 |  | 
|---|
| 584 | my $as_in_svn = saveAsInSVNforDir($dir); | 
|---|
| 585 |  | 
|---|
| 586 | opendir(DIR,$dir) || die "can't read directory '$dir' (Reason: $!)"; | 
|---|
| 587 | foreach (readdir(DIR)) { | 
|---|
| 588 | if ($_ ne '.' and $_ ne '..') { | 
|---|
| 589 | my $full = $dir.'/'.$_; | 
|---|
| 590 |  | 
|---|
| 591 | # print STDERR "full='$full' (as_in_svn=$as_in_svn)\n"; | 
|---|
| 592 |  | 
|---|
| 593 | if (not -l $full) { | 
|---|
| 594 | if (-d $full) { | 
|---|
| 595 | if ($as_in_svn==1) { | 
|---|
| 596 | if (is_version_controlled($_,%CVS)==1) { | 
|---|
| 597 | push @subdirs, $full; | 
|---|
| 598 | } | 
|---|
| 599 | } | 
|---|
| 600 | else { | 
|---|
| 601 | if (useDir($full)==1) { | 
|---|
| 602 | expectVCmember($full,$_,%CVS); | 
|---|
| 603 | push @subdirs, $full; | 
|---|
| 604 | } | 
|---|
| 605 | else { unexpectVCmember($full,$_,%CVS); } | 
|---|
| 606 | } | 
|---|
| 607 | } | 
|---|
| 608 | elsif (-f $full) { | 
|---|
| 609 | if ($as_in_svn==1) { | 
|---|
| 610 | if (is_version_controlled($_,%CVS)==1) { | 
|---|
| 611 | push @files, $full; | 
|---|
| 612 | } | 
|---|
| 613 | } | 
|---|
| 614 | else { | 
|---|
| 615 | if (useFile($dir,$_)==1) { | 
|---|
| 616 | expectVCmember($full,$_,%CVS); | 
|---|
| 617 | push @files, $full; | 
|---|
| 618 | } | 
|---|
| 619 | else { unexpectVCmember($full,$_,%CVS); } | 
|---|
| 620 | } | 
|---|
| 621 | } | 
|---|
| 622 | else { die "Unknown (neighter link nor file nor directory): '$full'"; } | 
|---|
| 623 | } | 
|---|
| 624 | } | 
|---|
| 625 | } | 
|---|
| 626 | closedir(DIR); | 
|---|
| 627 |  | 
|---|
| 628 | foreach (@files) { print $_."\n"; } | 
|---|
| 629 | foreach (@subdirs) { dumpFiles($_); } | 
|---|
| 630 | }; | 
|---|
| 631 | if ($@) { | 
|---|
| 632 | my $err = $@; | 
|---|
| 633 | if ($err =~ /at\s(.*\.pl)\sline\s([0-9]+)/) { | 
|---|
| 634 | $err = "$1:$2: Error: $`"; | 
|---|
| 635 | } | 
|---|
| 636 | $err =~ s/\n//g; | 
|---|
| 637 | die "$err\n"; | 
|---|
| 638 | } | 
|---|
| 639 | } | 
|---|
| 640 |  | 
|---|
| 641 | my $args = scalar(@ARGV); | 
|---|
| 642 | if ($args==0) { | 
|---|
| 643 | dumpFiles('.'); | 
|---|
| 644 | } | 
|---|
| 645 | else { | 
|---|
| 646 | my $arg = $ARGV[0]; | 
|---|
| 647 | if ($arg eq 'ignore') { | 
|---|
| 648 | $ignore_unknown = 1; | 
|---|
| 649 | dumpFiles('.'); | 
|---|
| 650 | } | 
|---|
| 651 | elsif ($arg eq 'matching') { | 
|---|
| 652 | $debug_matching = 1; | 
|---|
| 653 | dumpFiles('.'); | 
|---|
| 654 | } | 
|---|
| 655 | else { | 
|---|
| 656 | die "Usage: arb_srclst.pl [ignore|matching]\n"; | 
|---|
| 657 | } | 
|---|
| 658 | } | 
|---|