diff options
Diffstat (limited to 'support/splint/scripts/brack.pl')
-rwxr-xr-x | support/splint/scripts/brack.pl | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/support/splint/scripts/brack.pl b/support/splint/scripts/brack.pl new file mode 100755 index 0000000000..6e110e5cf3 --- /dev/null +++ b/support/splint/scripts/brack.pl @@ -0,0 +1,105 @@ +#!/usr/bin/perl + +# a simple script to replace all @G ... @`other' regions with +# @= ... @>@; lines +# comments are allowed at the end of the lines. +# only one style of comments is accepted: /* ... */. note that these are not +# output + +open FILE, "$ARGV[0]" or die "Cannot open input file $ARGV[0]\n"; +open FILEOUT, ">$ARGV[1]" or die "Cannot open output file $ARGV[1]\n"; + +$state = 0; +while (<FILE>) { + + $inline = $_; + + + if ( $inline =~ m/^\@G(.*)$/ ) { # @G detected, this line is part of the `other language' region + + $inline = $1; $state = 1; + if ( $inline =~ m/^\(([^)]*)\).*/ ) { + printf FILEOUT "\@q Start generic language section\@>\n\@t}\\begingsec{%s}{\@>\n", "$1"; # a parser switcher + } else { + $inline = " Start \@\@G (generic) language section"; + printf FILEOUT "\@q%s\@>\n\@t}\\begingsec{b}{\@>\n", "$inline"; # a parser switcher + } + + } elsif ( $inline =~ m/^\@[\scp].*$/ ) { # @`other' detected, so `other language' region is over + + if ($state == 1) { + printf FILEOUT "\@q%s\@>\n\@t}\\endgsec{\@>\n", + "End of generic language section"; # a parser switcher + } + $state = 0; + printf FILEOUT "%s", "$inline"; + + } elsif ( $inline =~ m/^\s*\@[=t].*$/ ) { # @= detected, just copy the line + + printf FILEOUT "%s", "$inline"; + + } elsif ( $inline =~ m/^\@g(.*)$/ ) { # @`other' detected, so `other language' region is over + + if ($state == 1) { + printf FILEOUT "\@q%s\@>\n\@t}\\endgsec{\@>\n", + "End of generic language section"; # a parser switcher + } + + $inline = $1; $state = 0; + + if ( not $inline ) { $inline = "End generic language section"; } + printf FILEOUT "\@q%s\@>\n", "$inline"; + + } elsif ( $inline =~ m/^\@O(.*)$/ ) { # @O detected, so `other language' region is paused + + $inline = $1; $state = 0; + + if ( not $inline ) { $inline = "End generic language section"; } + printf FILEOUT "\@q%s\@>\n", "$inline"; + + } elsif ( $inline =~ m/^\@o(.*)$/ ) { # @o detected, so `other language' region is resumed + + $inline = $1; $state = 1; + + if ( not $inline ) { $inline = "End generic language section"; } + printf FILEOUT "\@q%s\@>\n", "$inline"; + + } elsif ( $state == 1 ) { + + if ( $inline =~ m/\/\*.*\*\/\s*$/ ) { + + $inline =~ m/^(.*\S|)\s*(\/\*.*\*\/)\s*$/; + $string = $1; $comment = $2; + + } else { + + $inline =~ m/^(.*)$/; + $string = $1; $comment = ""; + + } + + if ( $string ) { + + printf FILEOUT "\@=%s\@>\@;", "$string"; + + } else { + + printf FILEOUT "\@=%s\@>\@;", " "; + + } + + if ( $comment ) { + + printf FILEOUT "%s", "$comment"; + + } + + printf FILEOUT "%s", "\n"; + + } else { + + printf FILEOUT "%s", "$inline"; + + } + +} |