Updated CASC scripts, as provided to Geoff Sutcliffe
[cvc5.git] / contrib / extract-strings-and-comments
1 #!/usr/bin/perl -0777
2
3 my $debug = 0;
4
5 $_ = <>;
6 my $comments = "";
7 my $code = "";
8
9 # ignore strings and comments appearing in preprocessor directives
10 s/^#.*//mg;
11
12 for(;;) {
13 s,^([^"/]+),,;
14 $code .= "$1\n";
15
16 if(m,^([^"]*)"",) {
17 s,^([^"]*)"",,s;
18 $code .= "$1\n";
19 next;
20 }
21 if(m,^([^"]*)"([^"]*)",) {
22 s,^([^"]*)"(([^\\"]*?([^\\"]|(\\.)))+)",,s;
23 print STDERR "quote: $2\n" if $debug;
24 $code .= "$1\n";
25 $comments .= "$2\n";
26 next;
27 }
28 if(m,/\*.*?\*/,) {
29 s,/\*(.*?)\*/,,s;
30 print STDERR "c-style comment: $1\n" if $debug;
31 $comments .= "$1\n";
32 print STDERR "REMAINDER:\n===========================\n$_\n=========================\n" if $debug;
33 next;
34 }
35 if(m,//,) {
36 s,//([^\n]*),,s;
37 print STDERR "c++-style comment: $1\n" if $debug;
38 $comments .= "$1\n";
39 print STDERR "REMAINDER:\n===========================\n$_\n=========================\n" if $debug;
40 next;
41 }
42 last;
43 }
44
45 $code .= "$_\n";
46 $code =~ s,\W+,\n,g;
47 $code =~ s,^,@,gm;
48 print "$code\n";
49
50 $comments =~ s,^,^,gm;
51 print "$comments\n";
52