zlib2ansi revision 1b33c96954667ba382fa595baf7b31290bfdd517
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Transform K&R C function definitions into ANSI equivalent.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Author: Paul Marquess
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Version: 1.0
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Date: 3 October 2006
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Asumes no function pointer parameters. unless they are typedefed.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Assumes no literal strings that look like function definitions
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Assumes functions start at the beginning of a line
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncmy $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncmy $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncmy $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync \s* \) # optional whitespace surrounding a Literal ")"
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync my $i = 0 ;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync my @params = split /\s*;\s*/, $params;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync my @bits = split /\s*,\s*/, $p;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync my $first = shift @bits;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync $first =~ s/^\s*//;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync $p =~ s/^\s+//;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Output any trailing code.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [^/*][^*]*\*+
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [^\n]* ## followed by 0-or-more non end of line characters
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync \\. ## Escaped char
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ' ## Start of ' ... ' string
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync \\. ## Escaped char
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync [^'\\] ## Non '\
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ' ## End of ' ... ' string
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync . ## Anything other char