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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Revision: 8738 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.7.0/scripts/msg_parse $
#$Date: 2021-04-28 19:35:53 +0300 (Wed, 28 Apr 2021) $
#$Id: cif_diff 3294 2015-04-22 10:12:45Z andrius $
#------------------------------------------------------------------------------
#*
#* Parse COD error messages and output the results in the desired format.
#*
#* USAGE:
#* $0 --options input1.cif input*.cif
#**
use strict;
use warnings;
use COD::SOptions qw( getOptions );
use COD::SUsage qw( usage options );
use COD::UserMessage qw( parse_message note );
use COD::ToolsVersion qw( get_version_string );
my $ignore_comments = 0;
my @dsv_print_order = ( qw(
program
filename
line_no
column_no
add_pos
err_level
message
) );
my $print_options = {
'format' => 'dsv',
'delimiter' => "\t",
'dsv_order' => \@dsv_print_order
};
#* OPTIONS:
#* -d, --delimiter "\t"
#* Delimiter that is used to separate fields in the
#* delimiter-separated values (dsv) output format
#* (default: "\t").
#* --dsv
#* Output results in delimiter-separated values (dsv)
#* format (default).
#* --ignore-comments
#* Ignore lines starting with a number symbol ('#').
#* --process-comments
#* Treat lines starting with a number symbol ('#') as
#* error messages (default).
#* --help, --usage
#* Output a short usage message (this message) and exit.
#* --version
#* Output version information and exit.
#**
@ARGV = getOptions(
"-d,--delimiter" => \$print_options->{delimiter},
"--dsv" => sub { $print_options->{format} = 'dsv' },
"--ignore-comments" => sub { $ignore_comments = 1 },
"--process-comments" => sub { $ignore_comments = 0 },
'--options' => sub { options; exit },
'--help,--usage' => sub { usage; exit },
'--version' => sub { print get_version_string(), "\n"; exit }
);
my $msg;
while (<>) {
next if $ignore_comments && $_ =~ /^\s*#/ ;
if ( !defined $msg ) {
$msg = $_;
} elsif ( /^ / && $msg =~ /[^ ].*:\s*$/m) {
$msg .= $_;
} else {
print_parsed_msg($msg, $print_options);
$msg = $_;
}
if (eof) {
print_parsed_msg($msg, $print_options);
}
}
sub print_parsed_msg
{
my ($msg, $options) = @_;
my $format = $options->{format};
my $delim = $options->{delimiter};
my $order = $options->{dsv_order};
my $parsed_msg = parse_message( $msg );
if ( defined $parsed_msg ) {
if ( $format eq 'dsv' ) {
print join $delim, map { ( defined $parsed_msg->{$_} ) ?
$parsed_msg->{$_} :
'' } @{$order};
if ( defined $parsed_msg->{line_content} ) {
print "\t\n$parsed_msg->{line_content}"
} else {
print "\n";
};
}
} else {
chomp($msg);
note( {
'program' => $0,
'filename' => $ARGV,
'message' => "unable to parse error message '$msg'"
} );
}
return;
};
|