Add Folding section link to filetypes.common custom settings.
[geany-mirror.git] / plugins / genapi.py
blobb80684dff4aaf6b2f70bc9462a81463571203f13
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # genapi.py - this file is part of Geany, a fast and lightweight IDE
6 # Copyright 2008-2010 Nick Treleaven <nick.treleaven<at>btinternet.com>
7 # Copyright 2008-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 # $(Id)
25 r"""
26 Creates macros for each plugin API function pointer, e.g.:
28 #define plugin_add_toolbar_item \
29 geany_functions->p_plugin->plugin_add_toolbar_item
30 """
33 import re, sys
35 def get_function_names():
36 names = []
37 filep = open('../src/plugins.c')
38 while 1:
39 line = filep.readline()
40 if line == "":
41 break
42 match = re.match("^\t&([a-z][a-z0-9_]+)", line)
43 if match:
44 symbol = match.group(1)
45 if not symbol.endswith('_funcs'):
46 names.append(symbol)
47 filep.close()
48 return names
50 def get_api_tuple(source):
51 match = re.match("^([a-z]+)_([a-z][a-z0-9_]+)$", source)
52 return 'p_' + match.group(1), match.group(2)
55 header = \
56 r'''/* This file is generated automatically by genapi.py - do not edit. */
58 /** @file %s @ref geany_functions wrappers.
59 * This allows the use of normal API function names in plugins by defining macros.
61 * E.g.:@code
62 * #define plugin_add_toolbar_item \
63 * geany_functions->p_plugin->plugin_add_toolbar_item @endcode
65 * You need to declare the @ref geany_functions symbol yourself.
67 * Note: This must be included after all other API headers to prevent conflicts with
68 * other header's function prototypes - this is done for you when using geanyplugin.h.
71 #ifndef GEANY_FUNCTIONS_H
72 #define GEANY_FUNCTIONS_H
73 '''
75 if __name__ == "__main__":
76 outfile = 'geanyfunctions.h'
78 fnames = get_function_names()
79 if not fnames:
80 sys.exit("No function names read!")
82 f = open(outfile, 'w')
83 print >> f, header % (outfile)
85 for fname in fnames:
86 ptr, name = get_api_tuple(fname)
87 # note: name no longer needed
88 print >> f, '#define %s \\\n\tgeany_functions->%s->%s' % (fname, ptr, fname)
90 print >> f, '\n#endif'
91 f.close()
93 if not '-q' in sys.argv:
94 print 'Generated ' + outfile