blob: ea0fc1b394cc5182f5360d0e8fba5c0cb2c6cb52 (
plain)
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
|
#!/usr/bin/perl
#
# Copyright (C) 2009-2010 Yuki Manabe and Daniel M. German
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# this is to extract the first <n> comments from any language that
# uses the same prefix
use Getopt::Std;
# set parameters
my %opts = ();
if (!getopts ("vc:p:",\%opts)) {
print STDERR "Usage $0 -v
-v verbose
-p comment char
-c count of comment blocks
\n";
die;
}
my $f = $ARGV[0];
open (OUT, ">${f}.comments") or die "Unable to create [${f}.comments]";
<>;
print OUT unless /^\#\!/;
my $commentChar = '#';
$commentChar = $opts{p} if exists $opts{p};
my $numberComments = 1;
$numberComments = $opts{c} if exists $opts{c};
my $verbose = exists $opts{v};
my $insideComment = 0;
my $insideCode = 0;
my $comCount = 0;
my $countCode = 0;
while (<>) {
chomp;
if (Is_Comment($_)) {
s/\t/ /g;
s/ +/ /g;
$comCount ++ if (not $insideComment);
$insideComment = 1;
/$commentChar+/;
print OUT $' . "\n"; #'
} elsif (Is_Blank($_)) {
print OUT "\n";
} else {
exit 0;
}
}
sub Is_Comment
{
my ($st) = @_;
return ($st =~ /^\s*$commentChar/);
}
sub Is_Blank
{
my ($st) = @_;
return ($st =~ /^\s*$/);
}
|