1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | sub die_usage($) { |
---|
7 | my ($err) = @_; |
---|
8 | die ("Usage: ./quietly.pl XMLLINT xmlfile\n". |
---|
9 | " Validates an XML file.\n". |
---|
10 | " Error messages are converted into readable format\n". |
---|
11 | " and superfluous output is suppressed\n". |
---|
12 | "Error: $err"); |
---|
13 | } |
---|
14 | |
---|
15 | my $basedir = $ENV{ARBHOME}; if (not -d $basedir) { die "no such directory '$basedir'"; } |
---|
16 | $basedir .= '/HELP_SOURCE'; if (not -d $basedir) { die "no such directory '$basedir'"; } |
---|
17 | |
---|
18 | my $args = scalar(@ARGV); |
---|
19 | if ($args != 2) { die_usage "Expected 2 arguments"; } |
---|
20 | |
---|
21 | my $tool = $ARGV[0]; |
---|
22 | my $xmlfile = $ARGV[1]; |
---|
23 | |
---|
24 | if ($tool ne 'XMLLINT') { die_usage "Expected 'XMLLINT' as 1st arg (not '$tool')"; } |
---|
25 | |
---|
26 | my $tool_command = "xmllint --valid --noout $xmlfile 2>&1 >/dev/null"; |
---|
27 | |
---|
28 | my $tool_out = `$tool_command`; |
---|
29 | if ($? == -1) { die "Failed to execute '$tool_command'" } |
---|
30 | elsif ($? & 127) { die sprintf("Executed command '$tool_command'\ndied with signal %d", ($? & 127)); } |
---|
31 | else { |
---|
32 | my $tool_exitcode = ($? >> 8); |
---|
33 | if ($tool_exitcode!=0) { |
---|
34 | my $sep = '------------------------------------------------------------'; |
---|
35 | # print "$sep\n"; |
---|
36 | # print "Error executing '$tool_command' (exitcode=$tool_exitcode):\n"; |
---|
37 | |
---|
38 | # print "$sep plain:\n"; |
---|
39 | # print $tool_out; |
---|
40 | # print "$sep end of plain\n"; |
---|
41 | |
---|
42 | use Cwd; |
---|
43 | my $cwd = getcwd(); |
---|
44 | my $cwdlen = length($cwd); |
---|
45 | my $file_prefix = 'file://'.$cwd.'/'; |
---|
46 | |
---|
47 | # print "file_prefix='$file_prefix'\n"; |
---|
48 | |
---|
49 | my @output = (); |
---|
50 | while ($tool_out =~ /\n/g) { |
---|
51 | $tool_out = $'; |
---|
52 | push @output, $`; |
---|
53 | } |
---|
54 | if (length $tool_out) { push @output, $tool_out; } |
---|
55 | |
---|
56 | my $last_line = undef; |
---|
57 | foreach (@output) { |
---|
58 | if (/^([^:\s]+):([0-9]+):\s*(.*)$/o) { print "$basedir/$1:$2: $3\n"; } |
---|
59 | else { print "Add.info: '$_'\n"; } |
---|
60 | } |
---|
61 | die "$sep $tool failed!\n"; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | |
---|