Synchronize popup menu and plugin preferences dialog 'Show Hidden
[geany-mirror.git] / scripts / fix-cxx-comments.pl
blob51ae5423fab37e3703d3172980fbbaba3081ad7a
1 #!/usr/bin/env perl
2 # fix-cxx-comments.pl
3 # Copyright (c) 2008, Daniel Richard G. <skunk(at)iskunk(dot)org>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of the author nor the names of
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 use strict;
32 use warnings;
34 sub xform($$$)
36 my ($a, $b, $c) = @_;
38 $a =~ s!///!/**!;
39 $b =~ s!(\a\s*)///!$1 **!g;
40 $c =~ s!///! **!;
42 $a =~ s!//!/*!;
43 $b =~ s!(\a\s*)//!$1 *!g;
44 $c =~ s!//! *!;
46 $c .= ' */';
48 return $a . $b . $c . "\a";
51 sub fix_cxx_comments()
53 s/\r//g; # This is Unix, not DOS
54 s/[\t ]+$//g; # Remove trailing whitespace
55 s/\n/\a/g; # Convert file to single line
57 # Process multi-line comments:
58 # $1 = first line of comment, $3 = last line, $2 = lines in between
59 s! (\a\s*//[^\a]*) ((?:\a\s*//[^\a]*)*) (\a\s*//[^\a]*)\a !xform($1,$2,$3)!egx;
61 # Process /// single-line comments
62 s! (\a\s*)///(\s?)([^\a]*)\a !$1/**$2$3$2*/\a!gx;
63 s! (\s+)///(\s?)([^\a]*)\a !$1/**$2$3$2*/\a!gx;
65 # Process // single-line comments
66 s! (\a\s*)//(\s?)([^\a]*)\a !$1/*$2$3$2*/\a!gx;
67 s! (\s+)//(\s?)([^\a]*)\a !$1/*$2$3$2*/\a!gx;
69 s/\a/\n/g; # Convert back to multiple lines
73 local $/;
74 $_ = <>;
75 fix_cxx_comments();
76 print;