Skip to content
This repository
Browse code

Add 2 scripts from Daniel Richard G. to replace C++ line comments and…

… to show a summary of gcc warnings.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2989 ea778897-0a13-0410-b9d1-a72fbfd435f5
  • Loading branch information...
commit f3af26025ec2a5fab6fcfde5eba212207a54b6f3 1 parent bf3ea6c
Nick Treleaven ntrel authored

Showing 2 changed files with 156 additions and 0 deletions. Show diff stats Hide diff stats

  1. +78 0 scripts/fix-cxx-comments.pl
  2. +78 0 scripts/warning-summary.pl
78 scripts/fix-cxx-comments.pl
... ... @@ -0,0 +1,78 @@
  1 +#!/usr/bin/env perl
  2 +# fix-cxx-comments.pl
  3 +# Copyright (c) 2008, Daniel Richard G. <skunk(at)iskunk(dot)org>
  4 +#
  5 +# Redistribution and use in source and binary forms, with or without
  6 +# modification, are permitted provided that the following conditions are
  7 +# met:
  8 +#
  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.
  18 +#
  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.
  30 +
  31 +use strict;
  32 +use warnings;
  33 +
  34 +sub xform($$$)
  35 +{
  36 + my ($a, $b, $c) = @_;
  37 +
  38 + $a =~ s!///!/**!;
  39 + $b =~ s!(\a\s*)///!$1 **!g;
  40 + $c =~ s!///! **!;
  41 +
  42 + $a =~ s!//!/*!;
  43 + $b =~ s!(\a\s*)//!$1 *!g;
  44 + $c =~ s!//! *!;
  45 +
  46 + $c .= ' */';
  47 +
  48 + return $a . $b . $c . "\a";
  49 +}
  50 +
  51 +sub fix_cxx_comments()
  52 +{
  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
  56 +
  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;
  60 +
  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;
  64 +
  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;
  68 +
  69 + s/\a/\n/g; # Convert back to multiple lines
  70 +}
  71 +
  72 +{
  73 + local $/;
  74 + $_ = <>;
  75 + fix_cxx_comments();
  76 + print;
  77 +}
  78 +
78 scripts/warning-summary.pl
... ... @@ -0,0 +1,78 @@
  1 +#!/usr/bin/env perl
  2 +# warning-summary.pl
  3 +# Copyright (c) 2008, Daniel Richard G. <skunk(at)iskunk(dot)org>
  4 +#
  5 +# Redistribution and use in source and binary forms, with or without
  6 +# modification, are permitted provided that the following conditions are
  7 +# met:
  8 +#
  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.
  18 +#
  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.
  30 +
  31 +use strict;
  32 +use warnings;
  33 +
  34 +use encoding 'utf8';
  35 +
  36 +binmode(STDIN, ":utf8");
  37 +
  38 +open(OUT, "| sort | uniq -c | sort -nr");
  39 +binmode(OUT, ":utf8");
  40 +
  41 +while (<>)
  42 +{
  43 + /warning:/ || next;
  44 + /near initialization for/ && next;
  45 + /shadowed declaration is here/ && next;
  46 + /\(this will be reported only once per input file\)/ && next;
  47 +
  48 + s/^.*: warning: //g;
  49 +
  50 + tr/\x{2018}\x{2019}/''/;
  51 +
  52 + s/\barg(ument|) \d+\b/arg$1 N/g;
  53 +
  54 + s/\b(type|function|variable|enumeration value|declaration of|argument N of|parameter|type of|type of bit-field|prototype for) '[^']+'/$1 'blah'/g;
  55 +
  56 + s/"[^"]+" (is not defined)/"BLAH" $1/g;
  57 +
  58 + s/'[^']+' (defined but not used)/'blah' $1/g;
  59 +
  60 + s/format '%\w+'/format '%blah'/g;
  61 +
  62 + s/'%\w+' printf format/'%blah' printf format/g;
  63 +
  64 + s/'\d+'/'NNN'/g;
  65 +
  66 + s/'[^']+' (declared 'static' but never defined)/'blah' $1/g;
  67 +
  68 + s/(missing braces around initializer for) '\w+'/$1 'blah'/g;
  69 +
  70 + s/(missing initializer for member) '\w+::\w+'/$1 'Foo::bar'/g;
  71 +
  72 + print OUT;
  73 +}
  74 +
  75 +close(OUT);
  76 +
  77 +# end warning-summary.pl
  78 +

0 comments on commit f3af260

Please sign in to comment.
Something went wrong with that request. Please try again.