6 my $debug = $ENV{DEBUG};
8 # This scripts finds DEPRECATEDIN declarations and converts them to
9 # C declarations with the corresponding OSSL_DEPRECATEDIN attribute
10 # macro. It also makes sure they are guarded them with a corresponding
11 # '#ifndef OPENSSL_NO_DEPRECATED', and pays extra attention to only have
12 # one such guard around a group of deprecations for the same version.
16 \( # The start of what we recurse on
18 (?> [^()]+ ) # Non-parens, without backtracking
20 (?-1) # Recurse to start of parens group
22 \) # The end of what we recurse on
25 my $deprecated_kw_re = qr/(DEPRECATEDIN)_(\d+_\d+(?:_\d+)?)/;
42 $headertext = <STDIN>;
44 $headertext =~ s/\R/\n/g;
47 my $last_cppspaces = '';
48 my $currentguard = "";
50 while ( $headertext =~ m/(.*?) # $1
54 (\#)(\s*)(if)?.*? # $3 ('#')
58 \s*$deprecated_kw_re\(.*?
70 my $test = $capture.$';
73 print STDERR "DEBUG: captured:\n$capture"
77 # Treat preprocessor lines (count spaces)
79 $cppspaces .= ' ' if (defined $5 && $5 eq 'if');
80 print STDERR "DEBUG: cpp spaces set to ", length($cppspaces), "\n"
83 } elsif ($test =~ m/^\s*$deprecated_re(.*?\n)/) {
84 # Treat DEPRECATEDIN_...
86 $deprecation = "OSSL_DEPRECATEDIN_$version $3;$5";
87 $after = $'; # Different from the previous!
88 print STDERR "DEBUG: changed to:\n$deprecation\n"
92 if ($currentguard ne ''
93 && (defined $version && $currentguard ne $version
94 || $before !~ /^\s*$/s)) {
95 print "#${last_cppspaces}endif\n";
96 $cppspaces = substr($cppspaces, 0, -1);
101 if ($currentguard eq '' && defined $version) {
102 $currentguard = $version;
103 print "#${cppspaces}ifndef OPENSSL_NO_DEPRECATED_$version\n";
104 $last_cppspaces = $cppspaces;
106 print STDERR "DEBUG: cpp spaces set to ", length($cppspaces), "\n"
111 $headertext = $after;
113 print "#endif\n" if $currentguard ne '';