summaryrefslogtreecommitdiffstats
path: root/contrib/serf/build/gen_def.py
blob: d10d8c88d55a606f58f692f89d73eefffd8815b8 (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
#!/usr/bin/env python
#
# gen_def.py :  Generate the .DEF file for Windows builds
#
# ====================================================================
#   Copyright 2002-2010 Justin Erenkrantz and Greg Stein
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
# ====================================================================
#
#
# Typically, this script is used like:
#
#    C:\PATH> python build/gen_def.py serf.h serf_bucket_types.h serf_bucket_util.h > build/serf.def
#

import re
import sys

# This regex parses function declarations that look like:
#
#    return_type serf_func1(...
#    return_type *serf_func2(...
#
# Where return_type is a combination of words and "*" each separated by a
# SINGLE space. If the function returns a pointer type (like serf_func2),
# then a space may exist between the "*" and the function name. Thus,
# a more complicated example might be:
#    const type * const * serf_func3(...
#
_funcs = re.compile(r'^(?:(?:\w+|\*) )+\*?(serf_[a-z][a-z_0-9]*)\(',
                    re.MULTILINE)

# This regex parses the bucket type definitions which look like:
#
#    extern const serf_bucket_type_t serf_bucket_type_FOO;
#
_types = re.compile(r'^extern const serf_bucket_type_t (serf_[a-z_]*);',
                    re.MULTILINE)


def extract_exports(fname):
  content = open(fname).read()
  exports = [ ]
  for name in _funcs.findall(content):
    exports.append(name)
  for name in _types.findall(content):
    exports.append(name)
  return exports

# Blacklist the serf v2 API for now
blacklist = ['serf_connection_switch_protocol',
             'serf_http_protocol_create',
             'serf_http_request_create',
             'serf_https_protocol_create']

if __name__ == '__main__':
  # run the extraction over each file mentioned
  import sys
  print("EXPORTS")

  for fname in sys.argv[1:]:
    funclist = extract_exports(fname)
    funclist = set(funclist) - set(blacklist)
    for func in funclist:
      print(func)
OpenPOWER on IntegriCloud