Change 33117 by [EMAIL PROTECTED] on 2008/01/29 23:38:53

        Integrate:
        [ 32784]
        Add script to check source code for ANSI-C violations.
        
        [ 32833]
        Add a small program that gets the C pre-processor to expand the macro
        passed on the command line.
        
        [ 32946]
        Subject: [PATCH Porting/manicheck]
        From: "Robin Barker" <[EMAIL PROTECTED]>
        Date: Thu, 10 Jan 2008 18:48:04 -0000
        Message-ID: <[EMAIL PROTECTED]>
        
        [ 33046]
        checkcfgvar.pl should also check Porting/config.sh "just in case".
        
        [ 33048]
        Teach checkcfgvar.pl that : is also a comment character in shell scripts

Affected files ...

... //depot/maint-5.10/perl/MANIFEST#7 integrate
... //depot/maint-5.10/perl/Porting/checkansi.pl#1 branch
... //depot/maint-5.10/perl/Porting/checkcfgvar.pl#2 integrate
... //depot/maint-5.10/perl/Porting/expand-macro.pl#1 branch
... //depot/maint-5.10/perl/Porting/manicheck#2 integrate

Differences ...

==== //depot/maint-5.10/perl/MANIFEST#7 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST#6~33113~      2008-01-29 14:22:25.000000000 -0800
+++ perl/MANIFEST       2008-01-29 15:38:53.000000000 -0800
@@ -3229,6 +3229,7 @@
 Porting/add-package.pl Add/Update CPAN modules that are part of Core
 Porting/apply          Apply patches sent by mail
 Porting/check83.pl     Check whether we are 8.3-friendly
+Porting/checkansi.pl   Check source code for ANSI-C violations
 Porting/checkAUTHORS.pl        Check that the AUTHORS file is complete
 Porting/checkcase.pl   Check whether we are case-insensitive-fs-friendly
 Porting/checkcfgvar.pl Check that config scripts define all symbols
@@ -3242,6 +3243,7 @@
 Porting/corecpan.pl    Reports outdated dual-lived modules
 Porting/corelist.pl    Generates data for Module::CoreList
 Porting/curliff.pl     Curliff or liff your curliffable files.
+Porting/expand-macro.pl        A tool to expand C macro definitions in the 
Perl source
 Porting/findrfuncs     Find reentrant variants of functions used in an 
executable
 Porting/findvars       Find occurrences of words
 Porting/fixCORE                Find and fix modules that generate warnings

==== //depot/maint-5.10/perl/Porting/checkansi.pl#1 (text) ====
Index: perl/Porting/checkansi.pl
--- /dev/null   2008-01-25 10:48:57.533235220 -0800
+++ perl/Porting/checkansi.pl   2008-01-29 15:38:53.000000000 -0800
@@ -0,0 +1,111 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+use 5.010;
+use File::Find;
+use IO::File;
+use Getopt::Long;
+use Pod::Usage;
+
+my %limits = (
+  c90 => {
+           'logical-source-line-length' => 509,
+         },
+  c99 => {
+           'logical-source-line-length' => 4095,
+         },
+);
+
+my %opt = (
+  std => 'c99',
+);
+
+GetOptions(\%opt, qw( logical-source-line-length=i std=s ))
+  && @ARGV && exists $limits{$opt{std}}
+    or pod2usage(2);
+
+for my $k (keys %{$limits{$opt{std}}}) {
+  $opt{$k} //= $limits{$opt{std}}{$k};
+}
+
+{
+  my $num = 1;
+
+  sub report
+  {
+    my $msg = shift;
+    my $info = join '', @_;
+
+    if ($info) {
+      $info =~ s/\R+$//;
+      $info =~ s/^/   #|\t/mg;
+      $info = "\n$info\n\n";
+    }
+
+    warn sprintf "[%d] %s(%d): %s\n%s",
+         $num++, $File::Find::name, $., $msg, $info;
+  }
+}
+
+find(sub {
+  /\.([ch]|xs)$/ or return;
+
+  my $fh = IO::File->new($_) or die "$_: $!\n";
+  my $ll = '';
+
+  while (defined(my $line = <$fh>)) {
+    report("trailing whitespace after backslash", $line)
+        if $line =~ /\\[[:blank:]]+$/;
+
+    $ll .= $line;
+
+    unless ($ll =~ /\\$/) {
+      if (length $ll > $opt{'logical-source-line-length'}) {
+        report(sprintf("logical source line too long (%d > %d)",
+                       length $ll, $opt{'logical-source-line-length'}), $ll);
+      }
+      $ll = '';
+    }
+  }
+}, @ARGV);
+
+__END__
+
+=head1 NAME
+
+checkansi.pl - Check source code for ANSI-C violations
+
+=head1 SYNOPSIS
+
+checkansi.pl [B<--std>=c90|c99]
+[B<--logical-source-line-length>=I<num>]
+<path> ...
+
+=head1 DESCRIPTION
+
+B<checkansi.pl> searches 
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--std>=c90|c99
+
+Choose the ANSI/ISO standard against which shall be checked.
+Defaults to C<c99>.
+
+=item B<--logical-source-line-length>=I<number>
+
+Maximum length of a logical source line. Overrides the default
+given by the chosen standard.
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright 2007 by Marcus Holland-Moritz <[EMAIL PROTECTED]>.
+
+This program is free software; you may redistribute it
+and/or modify it under the same terms as Perl itself.
+
+=cut

==== //depot/maint-5.10/perl/Porting/checkcfgvar.pl#2 (text) ====
Index: perl/Porting/checkcfgvar.pl
--- perl/Porting/checkcfgvar.pl#1~32694~        2007-12-22 01:23:09.000000000 
-0800
+++ perl/Porting/checkcfgvar.pl 2008-01-29 15:38:53.000000000 -0800
@@ -34,6 +34,7 @@
           "win32/config.vc64",
           "win32/config.ce",
           "configure.com",
+          "Porting/config.sh",
          );
 
 sub read_file {
@@ -86,7 +87,7 @@
     my %cfg;
     read_file($cfg,
              sub {
-                 return if /^\#/ || /^\s*$/;
+                 return if /^\#/ || /^\s*$/ || /^\:/;
                  if ($cfg eq 'configure.com') {
                      s/(\s*!.*|\s*)$//; # remove trailing comments or 
whitespace
                      return if ! /^\$\s+WC "(\w+)='(.*)'"$/;

==== //depot/maint-5.10/perl/Porting/expand-macro.pl#1 (text) ====
Index: perl/Porting/expand-macro.pl
--- /dev/null   2008-01-25 10:48:57.533235220 -0800
+++ perl/Porting/expand-macro.pl        2008-01-29 15:38:53.000000000 -0800
@@ -0,0 +1,58 @@
+#!perl -w
+use strict;
+
+use vars qw($trysource $tryout $sentinel);
+$trysource = "try.c";
+$tryout = "try.i";
+
+my $macro = shift;
+die "$0 macro [headers]" unless defined $macro;
+
+$sentinel = "$macro expands to";
+
+foreach($trysource, $tryout) {
+    die "You already have a $_" if -e $_;
+}
+
+if ([EMAIL PROTECTED]) {
+    open my $fh, '<', 'MANIFEST' or die "Can't open MANIFEST: $!";
+    while (<$fh>) {
+       push @ARGV, $1 if m!^([^/]+\.h)\t!;
+    }
+}
+
+my $args = '';
+
+while (<>) {
+    next unless /^#\s*define\s+$macro/;
+    my ($def_args) = /^#\s*define\s+$macro\(([^)]*)\)/;
+    if (defined $def_args) {
+       my @args = split ',', $def_args;
+       my $argname = "A0";
+       $args = '(' . join (', ', map {$argname++} [EMAIL PROTECTED]) . ')';
+    }
+    last;
+}
+
+open my $out, '>', $trysource or die "Can't open $trysource: $!";
+
+print $out <<"EOF";
+#include "EXTERN.h"
+#include "perl.h"
+#line 3 "$sentinel"
+$macro$args
+EOF
+
+close $out or die "Can't close $trysource: $!";
+
+system "make $tryout" and die;
+
+open my $fh, '<', $tryout or die "Can't open $tryout: $!";
+
+while (<$fh>) {
+    print if /$sentinel/o .. 1;
+}
+
+foreach($trysource, $tryout) {
+    die "Can't unlink $_" unless unlink $_;
+}

==== //depot/maint-5.10/perl/Porting/manicheck#2 (text) ====
Index: perl/Porting/manicheck
--- perl/Porting/manicheck#1~32694~     2007-12-22 01:23:09.000000000 -0800
+++ perl/Porting/manicheck      2008-01-29 15:38:53.000000000 -0800
@@ -76,8 +76,8 @@
 
 $" = "\n" if $l;
 
-unshift @xtra, "extra:"   if @xtra;
-unshift @miss, "missing:" if @miss;
+unshift @xtra, "extra:"   if @xtra && !$x;
+unshift @miss, "missing:" if @miss && !$m;
 
 print "@xtra\n", if @xtra && !$m;
 print "@miss\n"  if @miss && !$x;
End of Patch.

Reply via email to