summaryrefslogtreecommitdiff
path: root/doc/scripts/getfuncs.pl
blob: 18957af30467900e346039e24ba87ee3473e63c6 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}'
  & eval 'exec perl -wST "$0" $argv:q'
    if 0;

# Copyright (C) 2011-2012 Free Software Foundation, Inc.
# Copyright (C) 2013 Nikos Mavrogiannopoulos
#
# This file is part of GnuTLS.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# given a header file in stdin it will print all functions

my $line;
my $func_name;
my $prototype;

$state = 0;

# 0: scanning
# 1: comment
# 2: struct||enum||typedef func
# 3: function
# 4: inline function { }

sub function_print {
  my $prototype = shift @_;

  if ($prototype =~ m/^\s*\w\s+[A-Za-z0-9_]+[\s\*]+([A-Za-z0-9_]+)\s*\(.*/) {
    $func_name = $1;
  } elsif ($prototype =~ m/^\s*[A-Za-z0-9_]+[\s\*]+([A-Za-z0-9_]+)\s*\([^\)]+/) {
    $func_name = $1;
  } elsif ($prototype =~ m/^\s*\w+\s+\w+[\s\*]+([A-Za-z0-9_]+)\s*\([^\)]+/) {
    $func_name = $1;
  } elsif ($prototype =~ m/^[\s\*]*([A-Za-z0-9_]+)\s*\([^\)]+/) {
    $func_name = $1;
  } elsif ($prototype =~ m/^[\s\*]*[A-Za-z0-9_]+\s+([A-Za-z0-9_]+)/) {
    $func_name = $1;
  }

#print STDERR "function: $prototype\n";
  if ($func_name ne '' && ($func_name =~ m/^gnutls_.*/ || $func_name =~ m/dane_.*/ || $func_name =~ m/xssl_.*/)) {
    print $func_name . "\n";
  }
      
  return;
}

while ($line=<STDIN>) {

  next if ($line eq '');
# print STDERR "line($state): $line";

  #skip comments
  if ($state == 0) {
    if ($line =~ m/^\s*\/\*/) {

      next if ($line =~ m/\*\//);

      $state = 1;
      next;
    } elsif ($line =~ m/^\s*typedef\s+enum/ || $line =~ m/^\s*enum/ || 
             $line =~ m/^\s*struct/ || $line =~ m/^\s*typedef\s+struct/ ||
             $line =~ m/^\s*typedef/) {

      next if ($line =~ m/;/);
      $state = 2;
      next;
    } elsif ($line =~ m/^\s*extern\s+"C"/) {
      next;
    } elsif ($line =~ m/^\s*\{/) {
      next if ($line =~ m/\}/);
      $state = 4;
      next;
    } elsif ($line !~ m/^\s*extern/ && $line !~ m/^\s*typedef/ && $line !~ m/doc-skip/ && $line =~ m/^\s*\w/) {
      $state = 3;

      $prototype = "$line";
      $func_name = '';

      if ($line =~ m/;/) {
        function_print($prototype);
        $state = 0;
        next;
      }
    }
  } elsif ($state == 1) { # comment
    if ($line =~ m/\*\//) {
      $state = 0;
      next;
    }
  } elsif ($state == 2) { #struct||enum||typedef
    if ($line =~ m/;/) {
      $state = 0;
      next;
    }
  } elsif ($state == 3) { #possible function
    $prototype .= $line;
    
    if ($line =~ m/;/) {
      $state = 0;

      function_print($prototype);
    }
  } elsif ($state == 4) { #inline function to be skipped
    if ($line =~ m/\}/) {
      $state = 0;
      next;
    }
  }

}