File: remove_w3c_callback

package info (click to toggle)
lilypond 2.19.83-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 76,396 kB
  • sloc: cpp: 79,385; ansic: 75,071; lisp: 59,263; xml: 31,196; python: 22,406; sh: 8,159; yacc: 3,872; perl: 3,507; asm: 1,587; lex: 1,408; makefile: 1,048; tcl: 457; awk: 199; php: 53; csh: 50
file content (35 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

use warnings;
use strict;

use IO::File;
use File::Find;

# <a href="http://validator.w3.org/check?uri=referer">
# <img src="http://www.w3.org/Icons/valid-html401"
#      alt="Valid HTML 4.01 Transitional"
#      height="31" width="88"></a>

find(\&fix_if_file,@ARGV);

sub fix_if_file {
    return unless -f $_;
    my $fh = IO::File->new($_,'r') or
        die "Unable to open $_ for reading: $!";
    local $/;
    my $fc = <$fh>;
    close($fh);
    # strip out the w3c img callback; replace with alt text
    my $changed = $fc =~ s{<img\s+src="http://www.w3c?.org/Icons/[^"]+"[^>]*?alt="([^"]+)"[^>]*>}{$1}imsg;
    # if it doesn't have alt text, just replace it with Valid HTML
    $changed += $fc =~ s{<img\s+src="http://www.w3c?.org/Icons/[^"]+"[^>]*>}{Valid HTML}imsg;

    if ($changed) {
        $fh = IO::File->new($_,'w') or
            die "Unable to open $_ for writing: $!";
        print {$fh} $fc;
        close($fh);
        print STDERR "$File::Find::name was changed\n";
    }
}