summaryrefslogtreecommitdiff
path: root/graphics/pgplot/files/xf77
blob: 6e04a2ebdca7e01a2c4841a2eb4a2bf20f0f990e (plain) (blame)
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
#!/usr/bin/perl

$ftxt = "ipercent_val";
$ctxt = $ftxt . "__";
$myname = $0;

@names = ();
$count = 0;

while ($ARGV[0] =~ /^-/) {
    $opt .= " $ARGV[0]";
    if ($ARGV[0] eq "-o") {
	shift;
	$opt .= " $ARGV[0]";
    }
    shift;
}
if ("$opt" eq " -1") {&phase1;}
elsif ("$opt" eq " -2") {&phase2;}
else {
    $src = $ARGV[0];
    $tmp = $src;
    $tmp =~ s:.*/::;
    $tmp =~ s:f$:c:;
    $tmp = "/tmp/$tmp";
    system "$myname -1 < $src | f2c -f | $myname -2 > $tmp";
    system "cc -c $opt $tmp";
    unlink $tmp;
}
exit 0;

sub phase1 {
    while (<>) {
	s/%[Vv][Aa][Ll]/$ftxt/g;
	print $_;
    }
}
sub phase2 {
    while (<>) {
	if (/(\s*)(\w*)(\s*=\s*)($ctxt)/) {
	    $p = $2;
	    s/$ctxt\(&/\(/;
	    $names[$count] = $p;
	    $count++;
	    print $_;
	} else {
	    if ($count && /(\s*)(\w*)_\(/) {
		&repl ($_);
	    } else {
		print $_;
	    }
	}
    }
}

sub repl {
    $l = shift;
    while ($l) {
        foreach (@names) {
            $l =~ s/&$_/$_/g;
        }
        print $l;
        if ($l =~ /\);/) {
            @names = ();
            $count = 0;
            return;
        }
        $l = <>;
    }
}