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
|
#!/usr/bin/perl -0777
my $debug = 0;
$_ = <>;
my $comments = "";
my $code = "";
# ignore strings and comments appearing in preprocessor directives
s/^#.*//mg;
for(;;) {
s,^([^"/]+),,;
$code .= "$1\n";
if(m,^([^"]*)"",) {
s,^([^"]*)"",,s;
$code .= "$1\n";
next;
}
if(m,^([^"]*)"([^"]*)",) {
s,^([^"]*)"(([^\\"]*?([^\\"]|(\\.)))+)",,s;
print STDERR "quote: $2\n" if $debug;
$code .= "$1\n";
$comments .= "$2\n";
next;
}
if(m,/\*.*?\*/,) {
s,/\*(.*?)\*/,,s;
print STDERR "c-style comment: $1\n" if $debug;
$comments .= "$1\n";
print STDERR "REMAINDER:\n===========================\n$_\n=========================\n" if $debug;
next;
}
if(m,//,) {
s,//([^\n]*),,s;
print STDERR "c++-style comment: $1\n" if $debug;
$comments .= "$1\n";
print STDERR "REMAINDER:\n===========================\n$_\n=========================\n" if $debug;
next;
}
last;
}
$code .= "$_\n";
$code =~ s,\W+,\n,g;
$code =~ s,^,@,gm;
print "$code\n";
$comments =~ s,^,^,gm;
print "$comments\n";
|