Blame doc/scripts/getfuncs.pl

Packit 549fdc
#!/usr/bin/perl
Packit 549fdc
Packit 549fdc
# Copyright (C) 2011-2012 Free Software Foundation, Inc.
Packit 549fdc
# Copyright (C) 2013 Nikos Mavrogiannopoulos
Packit 549fdc
#
Packit 549fdc
# This file is part of GnuTLS.
Packit 549fdc
#
Packit 549fdc
# This file is free software; you can redistribute it and/or modify it
Packit 549fdc
# under the terms of the GNU General Public License as published by
Packit 549fdc
# the Free Software Foundation; either version 3 of the License, or
Packit 549fdc
# (at your option) any later version.
Packit 549fdc
#
Packit 549fdc
# This file is distributed in the hope that it will be useful, but
Packit 549fdc
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 549fdc
# General Public License for more details.
Packit 549fdc
#
Packit 549fdc
# You should have received a copy of the GNU General Public License
Packit 549fdc
# along with this file; if not, write to the Free Software Foundation,
Packit 549fdc
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 549fdc
Packit 549fdc
# given a header file in stdin it will print all functions
Packit 549fdc
Packit 549fdc
my $line;
Packit 549fdc
my $func_name;
Packit 549fdc
my $prototype;
Packit 549fdc
Packit 549fdc
$state = 0;
Packit 549fdc
Packit 549fdc
# 0: scanning
Packit 549fdc
# 1: comment
Packit 549fdc
# 2: struct||enum||typedef func
Packit 549fdc
# 3: function
Packit 549fdc
# 4: inline function { }
Packit 549fdc
Packit 549fdc
sub function_print {
Packit 549fdc
  my $prototype = shift @_;
Packit 549fdc
Packit 549fdc
  if ($prototype =~ m/^\s*\w\s+[A-Za-z0-9_]+[\s\*]+([A-Za-z0-9_]+)\s*\(.*/) {
Packit 549fdc
    $func_name = $1;
Packit 549fdc
  } elsif ($prototype =~ m/^\s*[A-Za-z0-9_]+[\s\*]+([A-Za-z0-9_]+)\s*\([^\)]+/) {
Packit 549fdc
    $func_name = $1;
Packit 549fdc
  } elsif ($prototype =~ m/^\s*\w+\s+\w+[\s\*]+([A-Za-z0-9_]+)\s*\([^\)]+/) {
Packit 549fdc
    $func_name = $1;
Packit 549fdc
  } elsif ($prototype =~ m/^[\s\*]*([A-Za-z0-9_]+)\s*\([^\)]+/) {
Packit 549fdc
    $func_name = $1;
Packit 549fdc
  } elsif ($prototype =~ m/^[\s\*]*[A-Za-z0-9_]+\s+([A-Za-z0-9_]+)/) {
Packit 549fdc
    $func_name = $1;
Packit 549fdc
  }
Packit 549fdc
Packit 549fdc
#print STDERR "function: $prototype\n";
Packit 549fdc
  if ($func_name ne '' && ($func_name =~ m/^gnutls_.*/ || $func_name =~ m/dane_.*/ || $func_name =~ m/xssl_.*/)) {
Packit 549fdc
    print $func_name . "\n";
Packit 549fdc
  }
Packit 549fdc
      
Packit 549fdc
  return;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
while ($line=<STDIN>) {
Packit 549fdc
Packit 549fdc
  next if ($line eq '');
Packit 549fdc
# print STDERR "line($state): $line";
Packit 549fdc
Packit 549fdc
  #skip comments
Packit 549fdc
  if ($state == 0) {
Packit 549fdc
    if ($line =~ m/^\s*\/\*/) {
Packit 549fdc
Packit 549fdc
      next if ($line =~ m/\*\//);
Packit 549fdc
Packit 549fdc
      $state = 1;
Packit 549fdc
      next;
Packit 549fdc
    } elsif ($line =~ m/^\s*typedef\s+enum/ || $line =~ m/^\s*enum/ || 
Packit 549fdc
             $line =~ m/^\s*struct/ || $line =~ m/^\s*typedef\s+struct/ ||
Packit 549fdc
             $line =~ m/^\s*typedef/) {
Packit 549fdc
Packit 549fdc
      next if ($line =~ m/;/);
Packit 549fdc
      $state = 2;
Packit 549fdc
      next;
Packit 549fdc
    } elsif ($line =~ m/^\s*extern\s+"C"/) {
Packit 549fdc
      next;
Packit 549fdc
    } elsif ($line =~ m/^\s*\{/) {
Packit 549fdc
      next if ($line =~ m/\}/);
Packit 549fdc
      $state = 4;
Packit 549fdc
      next;
Packit 549fdc
    } elsif ($line =~ m/^\s*#define/) {
Packit 549fdc
      next if ($line !~ m/\\$/);
Packit 549fdc
      $state = 5;
Packit 549fdc
      next;
Packit 549fdc
    } elsif ($line !~ m/^\s*extern/ && $line !~ m/^\s*typedef/ && $line !~ m/doc-skip/ && $line =~ m/^\s*\w/) {
Packit 549fdc
      $state = 3;
Packit 549fdc
Packit 549fdc
      $prototype = "$line";
Packit 549fdc
      $func_name = '';
Packit 549fdc
Packit 549fdc
      if ($line =~ m/;/) {
Packit 549fdc
        function_print($prototype);
Packit 549fdc
        $state = 0;
Packit 549fdc
        next;
Packit 549fdc
      }
Packit 549fdc
    }
Packit 549fdc
  } elsif ($state == 1) { # comment
Packit 549fdc
    if ($line =~ m/\*\//) {
Packit 549fdc
      $state = 0;
Packit 549fdc
      next;
Packit 549fdc
    }
Packit 549fdc
  } elsif ($state == 2) { #struct||enum||typedef
Packit 549fdc
    if ($line =~ m/;/) {
Packit 549fdc
      $state = 0;
Packit 549fdc
      next;
Packit 549fdc
    }
Packit 549fdc
  } elsif ($state == 3) { #possible function
Packit 549fdc
    $prototype .= $line;
Packit 549fdc
    
Packit 549fdc
    if ($line =~ m/;/) {
Packit 549fdc
      $state = 0;
Packit 549fdc
Packit 549fdc
      function_print($prototype);
Packit 549fdc
    }
Packit 549fdc
  } elsif ($state == 4) { #inline function to be skipped
Packit 549fdc
    if ($line =~ m/\}/) {
Packit 549fdc
      $state = 0;
Packit 549fdc
      next;
Packit 549fdc
    }
Packit 549fdc
  } elsif ($state == 5) { # define
Packit 549fdc
    if ($line !~ m/\\$/) {
Packit 549fdc
      $state = 0;
Packit 549fdc
      next;
Packit 549fdc
    }
Packit 549fdc
  }
Packit 549fdc
Packit 549fdc
}