3 #==============================================================================
5 # File ID: a6fde67c-bd88-11e7-93f2-f74d993421b0
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.0';
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 =~ /\#\#\#\#\#/ &&
97 $line =~ m
'/\* gncov \*/' &&
101 $c3 .= " /* gcov */";
103 print(to_fp
"$c3\n");
109 rename("$f.tmp", $f) or return 1;
114 # Print program version
115 print("$progname $VERSION\n");
120 # Send the help message to stdout
123 if ($Opt{'verbose'}) {
129 Usage: $progname [options] C_FILES [...]
131 Add "/* gcov */" markers to lines in .c files reported by gcov(1) as
141 Delete existing markers.
143 Mark lines even when they contain the gncov marker.
147 Be more quiet. Can be repeated to increase silence.
149 Increase level of verbosity. Can be repeated.
151 Print version information.
153 To suppress the gcov marker for some lines, add the string "/* gncov */"
154 to the relevant lines. This is for lines that are difficult to test
155 (full disk, memory full, long paths, etc).
162 # Print a status message to stderr based on verbosity level
163 my ($verbose_level, $Txt) = @_;
165 if ($Opt{'verbose'} >= $verbose_level) {
166 print(STDERR
"$progname: $Txt\n");
173 # This program is free software; you can redistribute it and/or modify it under
174 # the terms of the GNU General Public License as published by the Free Software
175 # Foundation; either version 2 of the License, or (at your option) any later
178 # This program is distributed in the hope that it will be useful, but WITHOUT
179 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
180 # FOR A PARTICULAR PURPOSE.
181 # See the GNU General Public License for more details.
183 # You should have received a copy of the GNU General Public License along with
185 # If not, see L<http://www.gnu.org/licenses/>.
187 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :