annotate src/zlib-1.2.7/zlib2ansi @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 8a15ff55d9af
children
rev   line source
cannam@89 1 #!/usr/bin/perl
cannam@89 2
cannam@89 3 # Transform K&R C function definitions into ANSI equivalent.
cannam@89 4 #
cannam@89 5 # Author: Paul Marquess
cannam@89 6 # Version: 1.0
cannam@89 7 # Date: 3 October 2006
cannam@89 8
cannam@89 9 # TODO
cannam@89 10 #
cannam@89 11 # Asumes no function pointer parameters. unless they are typedefed.
cannam@89 12 # Assumes no literal strings that look like function definitions
cannam@89 13 # Assumes functions start at the beginning of a line
cannam@89 14
cannam@89 15 use strict;
cannam@89 16 use warnings;
cannam@89 17
cannam@89 18 local $/;
cannam@89 19 $_ = <>;
cannam@89 20
cannam@89 21 my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments
cannam@89 22
cannam@89 23 my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ;
cannam@89 24 my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ;
cannam@89 25 my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ;
cannam@89 26
cannam@89 27
cannam@89 28 while (s/^
cannam@89 29 ( # Start $1
cannam@89 30 ( # Start $2
cannam@89 31 .*? # Minimal eat content
cannam@89 32 ( ^ \w [\w\s\*]+ ) # $3 -- function name
cannam@89 33 \s* # optional whitespace
cannam@89 34 ) # $2 - Matched up to before parameter list
cannam@89 35
cannam@89 36 \( \s* # Literal "(" + optional whitespace
cannam@89 37 ( [^\)]+ ) # $4 - one or more anythings except ")"
cannam@89 38 \s* \) # optional whitespace surrounding a Literal ")"
cannam@89 39
cannam@89 40 ( (?: $dList )+ ) # $5
cannam@89 41
cannam@89 42 $sp ^ { # literal "{" at start of line
cannam@89 43 ) # Remember to $1
cannam@89 44 //xsom
cannam@89 45 )
cannam@89 46 {
cannam@89 47 my $all = $1 ;
cannam@89 48 my $prefix = $2;
cannam@89 49 my $param_list = $4 ;
cannam@89 50 my $params = $5;
cannam@89 51
cannam@89 52 StripComments($params);
cannam@89 53 StripComments($param_list);
cannam@89 54 $param_list =~ s/^\s+//;
cannam@89 55 $param_list =~ s/\s+$//;
cannam@89 56
cannam@89 57 my $i = 0 ;
cannam@89 58 my %pList = map { $_ => $i++ }
cannam@89 59 split /\s*,\s*/, $param_list;
cannam@89 60 my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ;
cannam@89 61
cannam@89 62 my @params = split /\s*;\s*/, $params;
cannam@89 63 my @outParams = ();
cannam@89 64 foreach my $p (@params)
cannam@89 65 {
cannam@89 66 if ($p =~ /,/)
cannam@89 67 {
cannam@89 68 my @bits = split /\s*,\s*/, $p;
cannam@89 69 my $first = shift @bits;
cannam@89 70 $first =~ s/^\s*//;
cannam@89 71 push @outParams, $first;
cannam@89 72 $first =~ /^(\w+\s*)/;
cannam@89 73 my $type = $1 ;
cannam@89 74 push @outParams, map { $type . $_ } @bits;
cannam@89 75 }
cannam@89 76 else
cannam@89 77 {
cannam@89 78 $p =~ s/^\s+//;
cannam@89 79 push @outParams, $p;
cannam@89 80 }
cannam@89 81 }
cannam@89 82
cannam@89 83
cannam@89 84 my %tmp = map { /$pMatch/; $_ => $pList{$1} }
cannam@89 85 @outParams ;
cannam@89 86
cannam@89 87 @outParams = map { " $_" }
cannam@89 88 sort { $tmp{$a} <=> $tmp{$b} }
cannam@89 89 @outParams ;
cannam@89 90
cannam@89 91 print $prefix ;
cannam@89 92 print "(\n" . join(",\n", @outParams) . ")\n";
cannam@89 93 print "{" ;
cannam@89 94
cannam@89 95 }
cannam@89 96
cannam@89 97 # Output any trailing code.
cannam@89 98 print ;
cannam@89 99 exit 0;
cannam@89 100
cannam@89 101
cannam@89 102 sub StripComments
cannam@89 103 {
cannam@89 104
cannam@89 105 no warnings;
cannam@89 106
cannam@89 107 # Strip C & C++ coments
cannam@89 108 # From the perlfaq
cannam@89 109 $_[0] =~
cannam@89 110
cannam@89 111 s{
cannam@89 112 /\* ## Start of /* ... */ comment
cannam@89 113 [^*]*\*+ ## Non-* followed by 1-or-more *'s
cannam@89 114 (
cannam@89 115 [^/*][^*]*\*+
cannam@89 116 )* ## 0-or-more things which don't start with /
cannam@89 117 ## but do end with '*'
cannam@89 118 / ## End of /* ... */ comment
cannam@89 119
cannam@89 120 | ## OR C++ Comment
cannam@89 121 // ## Start of C++ comment //
cannam@89 122 [^\n]* ## followed by 0-or-more non end of line characters
cannam@89 123
cannam@89 124 | ## OR various things which aren't comments:
cannam@89 125
cannam@89 126 (
cannam@89 127 " ## Start of " ... " string
cannam@89 128 (
cannam@89 129 \\. ## Escaped char
cannam@89 130 | ## OR
cannam@89 131 [^"\\] ## Non "\
cannam@89 132 )*
cannam@89 133 " ## End of " ... " string
cannam@89 134
cannam@89 135 | ## OR
cannam@89 136
cannam@89 137 ' ## Start of ' ... ' string
cannam@89 138 (
cannam@89 139 \\. ## Escaped char
cannam@89 140 | ## OR
cannam@89 141 [^'\\] ## Non '\
cannam@89 142 )*
cannam@89 143 ' ## End of ' ... ' string
cannam@89 144
cannam@89 145 | ## OR
cannam@89 146
cannam@89 147 . ## Anything other char
cannam@89 148 [^/"'\\]* ## Chars which doesn't start a comment, string or escape
cannam@89 149 )
cannam@89 150 }{$2}gxs;
cannam@89 151
cannam@89 152 }