summaryrefslogtreecommitdiff
path: root/tools/repl-variadic
blob: 164ef4f4c757505fd4926c68635f50ae8500d618 (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
#!/usr/bin/env perl

# Replace the variadic functions mpfr_clears, mpfr_inits and mpfr_inits2,
# in case they are not supported by the compiler.
#
# Example of usage: perl -i tools/repl-variadic {src,tests}/*.{c,h}

use strict;

while (<>)
  {
    while (/\bmpfr_(clears|inits2?).*, *$/)
      { chomp; $_ .= <>; }
    my ($beg,$fct,$vars,$end) =
      /^(.*?) *\bmpfr_(clears|inits2?) *\((.*?), *\(mpfr_ptr\) *0\)(.*?)$/
        or print, next;
    print "$beg\n" if $beg ne '';
    my @vars = split /, */, $vars;
    $fct =~ tr/s//d;
    print "/* !!! Replaced with repl-variadic !!! */ do {\n";
    my $prec = '';
    if ($fct eq 'init2')
      {
        print "  mpfr_prec_t _repl_prec = (", shift(@vars), ");\n";
        $prec = ", _repl_prec";
      }
    foreach my $var (@vars)
      { print "  mpfr_$fct ($var$prec);\n" }
    print "} while (0)$end\n";
  }