source: branches/stable/HELP_SOURCE/quietly.pl

Last change on this file was 5892, checked in by westram, 16 years ago
  • use xmllint instead of rxp
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6sub 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
15my $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
18my $args = scalar(@ARGV);
19if ($args != 2) { die_usage "Expected 2 arguments"; }
20
21my $tool    = $ARGV[0];
22my $xmlfile = $ARGV[1];
23
24if ($tool ne 'XMLLINT') { die_usage "Expected 'XMLLINT' as 1st arg (not '$tool')"; }
25
26my $tool_command = "xmllint --valid --noout $xmlfile 2>&1 >/dev/null";
27
28my $tool_out = `$tool_command`;
29if ($? == -1) { die "Failed to execute '$tool_command'" }
30elsif ($? & 127) { die sprintf("Executed command '$tool_command'\ndied with signal %d", ($? & 127)); }
31else {
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
Note: See TracBrowser for help on using the repository browser.