| 1 |
1 |
moose |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
use warnings; |
| 5 |
|
|
use File::Spec; |
| 6 |
|
|
use File::Spec::Functions qw/splitdir catdir/; |
| 7 |
|
|
|
| 8 |
|
|
our $qrc = shift @ARGV; |
| 9 |
|
|
our $dir = shift @ARGV; |
| 10 |
|
|
our $indent = 0; |
| 11 |
|
|
|
| 12 |
|
|
open OUT, ">$qrc" or die "failed to open $qrc for writing: $!\n"; |
| 13 |
|
|
print OUT '<!DOCTYPE RCC>' . "\n" . '<RCC version="1.0">' . "\n"; |
| 14 |
|
|
|
| 15 |
|
|
scandir($dir); |
| 16 |
|
|
|
| 17 |
|
|
print OUT '</RCC>' . "\n"; |
| 18 |
|
|
|
| 19 |
|
|
sub scandir { |
| 20 |
|
|
my $dir = shift; |
| 21 |
|
|
local *DIR; |
| 22 |
|
|
if(!opendir DIR, $dir) { |
| 23 |
|
|
warn "failed to open $dir: $!\n"; |
| 24 |
|
|
return; |
| 25 |
|
|
} |
| 26 |
|
|
|
| 27 |
|
|
for(readdir DIR) { |
| 28 |
|
|
my $path = catdir($dir,$_); |
| 29 |
|
|
next if /^\..*$/; |
| 30 |
|
|
next if /^.*\.(?:cpp|qrc)$/; |
| 31 |
|
|
next if /^.*~$/; |
| 32 |
|
|
# print $path ."\n"; |
| 33 |
|
|
lstat $path; |
| 34 |
|
|
$path =~ s|^qrc/(.*)$|$1|; |
| 35 |
|
|
if(-d _) { |
| 36 |
|
|
if(!$indent) { |
| 37 |
|
|
print OUT '<qresource prefix="' . $_ . '">'; |
| 38 |
|
|
} |
| 39 |
|
|
|
| 40 |
|
|
$indent++; |
| 41 |
|
|
scandir(catdir("qrc", $path)); |
| 42 |
|
|
--$indent; |
| 43 |
|
|
|
| 44 |
|
|
if(!$indent) { |
| 45 |
|
|
print OUT "\n</qresource>\n"; |
| 46 |
|
|
} |
| 47 |
|
|
} |
| 48 |
|
|
=pod |
| 49 |
|
|
elsif(-l _) { |
| 50 |
|
|
my $link = readlink catdir("qrc", $path); |
| 51 |
|
|
|
| 52 |
|
|
print OUT "\n\t"x$indent; |
| 53 |
|
|
if($indent > 0) { |
| 54 |
|
|
my @dirs = splitdir($link); |
| 55 |
|
|
my $fn = pop @dirs; |
| 56 |
|
|
print OUT "<file alias=\"" . $fn . "\">$link</file>"; |
| 57 |
|
|
} else { |
| 58 |
|
|
print OUT "<file alias=\"" . $path . "\">" . $link . "</file>"; |
| 59 |
|
|
} |
| 60 |
|
|
} |
| 61 |
|
|
=cut |
| 62 |
|
|
elsif(-f _ || -l _) { |
| 63 |
|
|
print OUT "\n" . ("\t"x$indent); |
| 64 |
|
|
if($indent > 0) { |
| 65 |
|
|
my @dirs = splitdir($path); shift @dirs; |
| 66 |
|
|
my $npath = catdir(@dirs); |
| 67 |
|
|
print OUT "<file alias=\"" . $npath . "\">" . $path . "</file>"; |
| 68 |
|
|
} else { |
| 69 |
|
|
print OUT "<file alias=\"" . $path . "\">" . $path . "</file>"; |
| 70 |
|
|
} |
| 71 |
|
|
} |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
|
closedir DIR; |
| 75 |
|
|
} |