File: remove_extra_comments.pl

package info (click to toggle)
cp2k 2025.2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 372,052 kB
  • sloc: fortran: 963,262; ansic: 64,495; f90: 21,676; python: 14,419; sh: 11,382; xml: 2,173; makefile: 953; pascal: 845; perl: 492; cpp: 345; lisp: 297; csh: 16
file content (77 lines) | stat: -rwxr-xr-x 1,764 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl

=head1 NAME

remove_extra_comments.pl

=head1 SYNOPSIS

remove_extra_comments.pl [options] [infile]

=head1 OPTIONS

=over 4

=item B<infile>

Input file to process (uses stdin if not specified)

=item B<--help|-h>

A little help

=item B<--verbose|-v>

Output debug messages (to stderr), repeat for even more output

=back

=head1 DESCRIPTION

Remove any double sets of lines starting ! ******
E.g. removes the lines
! ****
! ****
These extra lines get created by the fixcomments.pl script because it's not
always guaranteed that a header will have them at the start and end and this
it will always add in the header lines.

=cut

use strict;
use warnings;
use open qw(:std :utf8);
use Pod::Usage qw(pod2usage);
use Getopt::Long;

my $verbose = 0;
my $help = 0;

GetOptions(
    'verbose+' => \$verbose,
    'help|?' => \$help) or pod2usage(2);
pod2usage(1) if $help;

sub print_debug {
    print(STDERR "DEBUG: @_\n") if ($verbose > 0);
}


my $count = 0;

while (my $currline = <>) { # While there are still lines to read
    # We want to strip out any double sets (i.e. lines next to each other of lines starting ! ****
    if ($currline =~ m/^!\s+\*+/i) {
        my $nextline = <>;  # If we get a match read in the next line
        while ($nextline eq $currline) {  # Keep reading until we find a different line
            $count += 1;  # Count up how many lines get stripped out
            $nextline = <>;
        }
        print $currline; # Dump out the ! ** and the next line that is not a duplicate
        print $nextline;
    } else {
        print $currline;  # Print out all the remainder of the file
    }
}

print_debug("remove_extra_comments.pl:: removed a total of ", $count, " duplicate comment lines from file", "\n");