1#!/usr/bin/env perl 2# 3# Copyright (C) 2017 Genome Research Ltd. 4# 5# Author: Anders Kaplan 6# 7# Permission is hereby granted, free of charge, to any person obtaining a copy 8# of this software and associated documentation files (the "Software"), to deal 9# in the Software without restriction, including without limitation the rights 10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11# copies of the Software, and to permit persons to whom the Software is 12# furnished to do so, subject to the following conditions: 13# 14# The above copyright notice and this permission notice shall be included in 15# all copies or substantial portions of the Software. 16# 17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23# DEALINGS IN THE SOFTWARE. 24 25use strict; 26 27my $log_message_count = 0; 28my $file_count = 0; 29my $failure_count = 0; 30 31sub check_log_message 32{ 33 my ($message, $filename, $line_num) = @_; 34 $log_message_count++; 35 36 unless ($message =~ /^\"([A-Z]|%s)/) 37 { 38 print "$filename line $line_num:\n"; 39 print "Log message should begin with a capital letter: $message.\n"; 40 $failure_count++; 41 } 42 43 if ($message =~ /\\n\"$/) 44 { 45 print "$filename line $line_num:\n"; 46 print "Log message should NOT end with a newline: $message.\n"; 47 $failure_count++; 48 } 49 50 if ($message =~ /\.\"$/) 51 { 52 print "$filename line $line_num:\n"; 53 print "Log message should NOT end with a full stop: $message.\n"; 54 $failure_count++; 55 } 56} 57 58sub check_file 59{ 60 my ($filename) = @_; 61 $file_count++; 62 63 open(my $fh, '<', $filename) or die "Could not open $filename."; 64 my $line_num = 1; 65 my $line = <$fh>; 66 while ($line) 67 { 68 if ($line =~ /hts_log_\w+\s*\(\s*(\"[^\"]*\")/) 69 { 70 unless ($line =~ /\\n\"\s*$/) # string constant continues on next line 71 { 72 check_log_message($1, $filename, $line_num); 73 } 74 } 75 76 $line_num++; 77 $line = <$fh>; 78 } 79} 80 81sub check_dir 82{ 83 my ($path) = @_; 84 foreach my $filename (glob("$path/*.c")) 85 { 86 check_file($filename); 87 } 88} 89 90check_dir(".."); 91check_dir("../cram"); 92 93print "$file_count files scanned\n"; 94print "$log_message_count log messages checked\n"; 95print "$failure_count errors found\n"; 96exit($failure_count > 0); 97