diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-01-22 18:38:54 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-01-22 18:38:54 +0000 |
commit | d07e5d1448fd2d464838d61971015423afc02358 (patch) | |
tree | 6df5f3d547b971da7cb83ec83ca3643c9ca5aba4 /lib/sbin/f_file_processor.pl | |
parent | e1eef87a273d2d6bbb1b0155b62bea4baceb7586 (diff) |
Fortran file preprocessor (was Breaklines). Forgot to commit earlier.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@114 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin/f_file_processor.pl')
-rw-r--r-- | lib/sbin/f_file_processor.pl | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/sbin/f_file_processor.pl b/lib/sbin/f_file_processor.pl new file mode 100644 index 00000000..a4cbbe07 --- /dev/null +++ b/lib/sbin/f_file_processor.pl @@ -0,0 +1,81 @@ +#!/usr/local/bin/perl +# +# Version: $Id$ +# +# New BreakLines routine which is much cleaner +# +# Reads STDIN, writes to STDOUT. +# +# replaces && with newline and tab to col 7 +# replaces &! with newline at col 0 +# Breaks lines greater than 72 cols +# Does this using multi-line matching! +# +# Paul, Jan 22 1995 +# Joan, Apr 21 1997: get rid of cC comments and handle ! comments properly +# and fix it so now it is really 72 and we do not get +# shitty breaks in the middle of fortran strings! +# +$* = 1; # Multi-line is on! + +while (<>) { + next if (/^\s*$/); # Blanks slow down compilation, and cpp makes + # lots and lots of them! + + next if (/^\#/); # Remove any remaining # directives (e.g. line directives). + + + # Get rid of final \n + chop; + + # Get rid of any tabs + s/\t/ /g; + + # OK, now put in the line breaks: + s/\&\&\s*/\n /g; + s/\&\!\s*/\n/g; + + # Get rid of standard c C comments + s/^[cC].*$/\n/g; + + # Get rid of ! comments : a bit tricky as ! may appear inside strings + s/(.)![^'"]*$/\1\n/g; + + s/\s*\;\s*$//; + + # And now we can fix the lines. This is actually a little complicated. + # since there is a different case if the thing matches a newline + # than if it doesn't. + if (/\n/) { + foreach $LINE (split('\n',$_)) { + &splitline($LINE); + } + } else { + &splitline($_); + } +} + +sub +splitline +{ + local ($LINE) = @_; + # Remove ,, and , \) from blank thorns + while ($LINE =~ s/,\s*,/,/) {} + $LINE =~ s/,\s*\)/\)/; + + # Strip out leading spaces in favor of 7 spaces + # $LINE =~ s/^\s+/ /; + # Note the new treatement of comments with \S + if ($LINE =~ /^([^\S].{71,71}).*/) { + print "$1\n"; + $LINE =~ s/.{72,72}//; + while ($LINE =~ /^(.{66,66}).*/) { + print " &$1\n"; + $LINE =~ s/.{66,66}//; + } + print " &$LINE\n"; + } else { + print "$LINE\n"; + } + +} |