3 #==============================================================================
5 # File ID: a6fde67c-bd88-11e7-93f2-f74d993421b0
7 # Add "/* gcov */" markers to lines in .c files reported by gcov(1) as unused.
10 # ©opyleft 2017– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of file for
13 #==============================================================================
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = '0.3.1';
36 Getopt
::Long
::Configure
('bundling');
39 'delete|d' => \
$Opt{'delete'},
40 'gncov|g' => \
$Opt{'gncov'},
41 'help|h' => \
$Opt{'help'},
42 'quiet|q+' => \
$Opt{'quiet'},
43 'verbose|v+' => \
$Opt{'verbose'},
44 'version' => \
$Opt{'version'},
46 ) || die("$progname: Option error. Use -h for help.\n");
48 $Opt{'verbose'} -= $Opt{'quiet'};
49 $Opt{'help'} && usage
(0);
50 if ($Opt{'version'}) {
61 msg
(1, "Processing $f");
62 if (process_file
($f)) {
63 print(STDERR
"$progname: $f: "
64 . "Error when processing file: $!\n");
75 open(from_fp
, "<$f") or return 1;
76 open(to_fp
, ">$f.tmp") or return 1;
77 while ($line = <from_fp
>) {
79 $line =~ s! /\* gcov \*/$!!;
80 print(to_fp
"$line\n");
84 printf(STDERR
"$progname: $f.gcov not found\n");
87 open(from_fp
, "<$f.gcov") or return 1;
88 open(to_fp
, ">$f.tmp") or return 1;
89 while ($line = <from_fp
>) {
91 if ($line =~ /^(.+?): +(\d+):(.*)$/) {
92 my ($c1, $c2, $c3) = ($1, $2, $3);
94 $c3 =~ s! /\* gcov \*/$!!;
95 if ($c1 =~ /\#\#\#\#\#/
96 && !($line =~ m
'/\* gncov \*/'
100 $c3 .= " /* gcov */";
102 print(to_fp
"$c3\n");
108 rename("$f.tmp", $f) or return 1;
113 # Print program version
114 print("$progname $VERSION\n");
119 # Send the help message to stdout
122 if ($Opt{'verbose'}) {
128 Usage: $progname [options] C_FILES [...]
130 Add "/* gcov */" markers to lines in .c files reported by gcov(1) as
140 Delete existing markers.
142 Mark lines even when they contain the gncov marker.
146 Be more quiet. Can be repeated to increase silence.
148 Increase level of verbosity. Can be repeated.
150 Print version information.
152 To suppress the gcov marker for some lines, add the string "/* gncov */"
153 to the relevant lines. This is for lines that are difficult to test
154 (full disk, memory full, long paths, etc).
161 # Print a status message to stderr based on verbosity level
162 my ($verbose_level, $Txt) = @_;
164 if ($Opt{'verbose'} >= $verbose_level) {
165 print(STDERR
"$progname: $Txt\n");
172 # This program is free software; you can redistribute it and/or modify it under
173 # the terms of the GNU General Public License as published by the Free Software
174 # Foundation; either version 2 of the License, or (at your option) any later
177 # This program is distributed in the hope that it will be useful, but WITHOUT
178 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
179 # FOR A PARTICULAR PURPOSE.
180 # See the GNU General Public License for more details.
182 # You should have received a copy of the GNU General Public License along with
184 # If not, see L<http://www.gnu.org/licenses/>.
186 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :