summaryrefslogtreecommitdiff
path: root/lib/sbin/f_file_processor.pl
blob: bbabbd2d9ae4857d715a91e0fa961583f0e6ff0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/my/bin/perl
#
# Version: $Id$
#
# New BreakLines routine which is much cleaner
#
# Reads STDIN, writes to STDOUT.
#
# removes all comments
# 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;
    
    # Get rid of standard c C, or even ! comments
    s/^[cC!].*$/\n/g;
    
    # Get rid of ! comments : a bit tricky as ! may appear inside strings
    s/(.)![^'"]*$/\1\n/g;

    # OK, now put in the line breaks (&& or &!)
    s/\&\&\s*/\n      /g;
    s/\&\!\s*/\n/g;

    # Get rid of lonesome semicolons
    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 
{
    my ($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";
    }

}