File: remove_comments.pl

package info (click to toggle)
unuran 1.11.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,344 kB
  • sloc: ansic: 204,607; sh: 4,783; perl: 3,160; makefile: 839; cpp: 24
file content (97 lines) | stat: -rwxr-xr-x 3,835 bytes parent folder | download | duplicates (2)
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
91
92
93
94
95
96
97
#!/usr/bin/perl
##############################################################################
#                                                                            #
#           UNURAN -- Universal Non-Uniform Random number generator          #
#                                                                            #
##############################################################################
#                                                                            #
#   FILE:    remove_comments.pl                                              #
#                                                                            #
#   Remove all comments and blank lines from given C source or header file   #
#                                                                            #
##############################################################################
#                                                                            #
#   Copyright (c) 2000-2006 Wolfgang Hoermann and Josef Leydold              #
#   Department of Statistics and Mathematics, WU Wien, Austria               #
#                                                                            #
#   This program is free software; you can redistribute it and/or modify     #
#   it under the terms of the GNU General Public License as published by     #
#   the Free Software Foundation; either version 2 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 General Public License for more details.                             #
#                                                                            #
#   You should have received a copy of the GNU General Public License        #
#   along with this program; if not, write to the                            #
#   Free Software Foundation, Inc.,                                          #
#   59 Temple Place, Suite 330, Boston, MA 02111-1307, USA                   #
#                                                                            #
##############################################################################

use strict;

my $DEBUG = 0;

############################################################

sub usage {
    my $progname = $0;
    $progname =~ s#^.*/##g;
        
    print STDERR <<EOM;
usage: $progname <file> 
      
Removes all comments and blank lines from C file <file>

EOM

    exit -1;
}

############################################################

# year
my $year = 1900 + (localtime(time))[5];

# read file name from argument list ...
my $file = shift;
(usage and die) unless $file;
print "stripping $file ...\n";

# open file ...
open IN, $file or die "cannot open file $file\n";
    
# read file ...
my $content = '';
while (<IN>) { $content .= $_; }
close IN;

# some comments must not be removed.
# so we first masks them
$content =~ s {/\*\s*FALLTHROUGH\s*\*/} [\@\@FALLTHROUGH\@\@]gsx;

# remove all comments and empty lines ...
$content =~ s {/\*.*?\*/} []gsx;
$content =~ s /\n\s*\n/\n/gsx;

# now unmask these special comments
$content =~ s {\@\@FALLTHROUGH\@\@} [/\* FALLTHROUGH \*/]gsx;

# copyright statment
my $copyright =
    "/* Copyright (c) 2000-$year Wolfgang Hoermann and Josef Leydold */\n" .
    "/* Department of Statistics and Mathematics, WU Wien, Austria  */\n";

# print into file
open OUT, ">$file";
print OUT $copyright;
print OUT $content;
close OUT;

# end
exit 0;

############################################################