This patch adds a script called "run_indent.pl" which runs the GNU indent
program to reformat code to conform to PDD 7.  It also patches PDD 7 to
reflect what is being done.

[josh-011.patch]

Index: MANIFEST
===================================================================
RCS file: /home/perlcvs/parrot/MANIFEST,v
retrieving revision 1.118
diff -u -r1.118 MANIFEST
--- MANIFEST    21 Feb 2002 18:04:32 -0000      1.118
+++ MANIFEST    24 Feb 2002 01:01:49 -0000
@@ -230,6 +230,7 @@
 register.c
 resources.c
 runops_cores.c
+run_indent.pl
 rx.c
 rx.ops
 rxstacks.c
Index: docs/pdds/pdd7.pod
===================================================================
RCS file: /home/perlcvs/parrot/docs/pdds/pdd7.pod,v
retrieving revision 1.1
diff -u -r1.1 pdd7.pod
--- docs/pdds/pdd7.pod  18 Feb 2002 17:47:18 -0000      1.1
+++ docs/pdds/pdd7.pod  24 Feb 2002 01:01:49 -0000
@@ -1,3 +1,6 @@
+
+
+
 =head1 TITLE
 
 Conventions and Guidelines for Perl Source Code
@@ -65,14 +68,14 @@
 boilerplate code must appear at the bottom of each source file. (This
 rule may be rescinded if I'm ever threatened with a lynching....)
 
-    /*
+   /*
     * Local variables:
     * c-indentation-style: bsd
     * c-basic-offset: 4
     * indent-tabs-mode: nil
-    * End
+    * End:
     *
-    * vim:expandtab shiftwidth=4:
+    * vim: expandtab shiftwidth=4:
     */
 
 
@@ -174,6 +177,53 @@
 
 =back
 
+To enforce the spacing, indenting, and bracing guidelines mentioned
+above, the following arguments to GNU Indent should be used:
+
+   -kr -nce -sc -cp0 -l79 -lc79 -psl -nut -cdw -ncs -lps
+
+This expands out to:
+   -nbad  Do not force blank lines after declarations.
+   -bap   Force blank lines after procedure bodies.
+   -bbo   Prefer to break long lines before boolean operators.
+   -nbc   Do not force newlines after commas in declarations
+   -br    Put braces on line with if, etc.
+   -brs   Put braces on struct declaration line.
+   -c33   Put comments to the right of code in column 33 (not recommended)
+   -cd33  Put declaration comments to the right of code in column 33
+   -ncdb  Do not put comment delimiters on blank lines.
+   -nce   Do not cuddle } and else.
+   -cdw   Do cuddle do { } while.
+   -ci4   Continuation indent of 4 spaces
+   -cli0  Case label indent of 0 spaces
+   -ncs   Do not put a space after a cast operator.
+   -d0    Set indentation of comments not to the right of code to 0 spaces.
+   -di1   Put declaration variables 1 space after their types
+   -nfc1  Do not format comments in the first column as  normal.
+   -nfca  Do not format any comments
+   -hnl   Prefer to break long lines at the position of newlines in the input.
+   -i4    4-space indents
+   -ip0   Indent parameter types in old-style function definitions by 0 spaces.
+   -l79   maximum line length for non-comment lines is 79 spaces.
+   -lc79  maximum line length for comment lines is 79 spaces.
+   -lp    maximum line length for non-comment lines is 79 spaces.
+   -npcs  Do not put a space after the function in function calls.
+   -nprs  Do not put a space after every ´(´ and before every ´)´.
+   -psl   Put the type of a procedure on the line before its name.
+   -saf   Put a space after each for.
+   -sai   Put a space after each if.
+   -saw   Put a space after each while.
+   -sc    Put the `*´ character at the left of comments.
+   -nsob  Do not swallow optional blank lines.
+   -nss   Do not force a space before the semicolon  after  certain statements
+   -nut   Use spaces instead of tabs.
+   -lps   Leave space between `#´ and preprocessor directive.
+
+Please note that it is also necessary to include all typedef types
+with the "-T" option to ensure that everything is formatted properly.
+
+A script (run_indent.pl) is be provided which runs indent properly for
+automatically.
 
 =head2 Naming conventions
 
@@ -256,6 +306,7 @@
 
 =back
 
+
 The top-level structure of the Perl source tarball should be as follows:
 
     /README, etc    a few top-level documents
@@ -272,6 +323,20 @@
     /pod/           src of the Perl man pages etc
 
 plus others as it becomes necessary.
+
+=item Header Files
+
+All .h files should include the following "guards" to prevent
+multiple-inclusion: 
+
+ /* file header comments */
+
+ #if !defined(PARROT_<FILENAME>_H_GUARD)
+ #define PARROT_<FILENAME>_H_GUARD
+
+ /* body of file */
+
+ #endif /* PARROT_<FILENAME>_H_GUARD */
 
 =item Names of code entities
 
--- /dev/null   Sat Jul 14 02:37:41 2001
+++ run_indent.pl       Sat Feb 23 19:57:30 2002
@@ -0,0 +1,72 @@
+#!/usr/bin/env perl
+
+die "Usage: $0 <c source files>\n" unless @ARGV;
+
+$|=1;
+use strict;
+use lib 'lib';
+
+use Parrot::Config;
+use C::Scan;
+
+my @incdirs;
+my $cc_inc  = $PConfig{'cc_inc'};
+my $ccflags = $PConfig{'ccflags'};
+while ($cc_inc  =~ s/-I(\S+)//g) { push @incdirs, $1; }
+while ($ccflags =~ s/-I(\S+)//g) { push @incdirs, $1; }
+my $i_flags = join ' ', map { "-I$_" } @incdirs;
+
+my %all_errors;
+foreach my $file (@ARGV) {
+    next unless ($file =~ /\.[ch]$/);
+    
+    print STDERR "Scanning $file..";
+    my $c = new C::Scan 'filename' => $file,
+                        'add_cppflags' => $ccflags;
+    $c->set('includeDirs' => \@incdirs);
+    
+    my $errors = 0;
+    local $SIG{__WARN__} = sub { $errors++; $all_errors{"@_"}=1; };
+    my $typedefs = $c->get('typedef_hash');
+
+    $/="\n";  # i don't know why, but this is necessary.
+    
+    my $defines = $c->get('defines_no_args_full');
+    foreach (keys %$defines) {
+       next unless (length($defines->{$_}) >= 3 &&
+                    $defines->{$_} !~ /\n/);
+         
+       $typedefs->{$_}="maybe";            
+    }
+   
+    
+    # now a little trick.  Weed out the ones we know aren't used.
+    open(F, "<$file") || die "Can't read $file: $!\n";
+    {
+        local $/=undef;
+        my $contents = <F>;
+
+       foreach (keys %$typedefs) {
+            delete $typedefs->{$_} unless ($contents =~ /\Q$_\E/);         
+       }
+    }
+    close(F);
+    
+    print STDERR "$errors parse errors.  " if ($errors);
+    print STDERR "Found " . scalar(keys %$typedefs) . " typedefs.\n";
+    my $cmd = "indent -kr -nce -sc -cp0 -l79 -lc79 -psl -nut -cdw -ncs -lps";
+    foreach (sort keys %$typedefs) {
+        $cmd .= " -T $_";
+    }
+    $cmd .= " $file";
+    
+    print "Running \"$cmd\"\n";
+    system($cmd);
+}   
+
+#if (%all_errors) {
+#    print STDERR "The following parse errors occurred:\n";
+#    foreach (sort keys %all_errors) {
+#        print;
+#    }
+#}


Reply via email to