Save encoding in session as text
[geany-mirror.git] / plugins / genapi.py
blob5c798f822a2d7c9a6f5a3625f105b96da98ac5b8
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-2011 Nick Treleaven <nick.treleaven<at>btinternet.com>
7 # Copyright 2008-2011 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
34 import sys
37 def get_function_names():
38 names = []
39 filep = open('../src/plugins.c')
40 while 1:
41 line = filep.readline()
42 if line == "":
43 break
44 match = re.match("^\t&([a-z][a-z0-9_]+)", line)
45 if match:
46 symbol = match.group(1)
47 if not symbol.endswith('_funcs'):
48 names.append(symbol)
49 filep.close()
50 return names
53 def get_api_tuple(source):
54 match = re.match("^([a-z]+)_([a-z][a-z0-9_]+)$", source)
55 return 'p_' + match.group(1), match.group(2)
58 header = \
59 r'''/* This file is generated automatically by genapi.py - do not edit. */
61 /** @file %s @ref geany_functions wrappers.
62 * This allows the use of normal API function names in plugins by defining macros.
64 * E.g.:@code
65 * #define plugin_add_toolbar_item \
66 * geany_functions->p_plugin->plugin_add_toolbar_item @endcode
68 * You need to declare the @ref geany_functions symbol yourself.
70 * Note: This must be included after all other API headers to prevent conflicts with
71 * other header's function prototypes - this is done for you when using geanyplugin.h.
74 #ifndef GEANY_FUNCTIONS_H
75 #define GEANY_FUNCTIONS_H
77 '''
79 if __name__ == "__main__":
80 outfile = 'geanyfunctions.h'
82 fnames = get_function_names()
83 if not fnames:
84 sys.exit("No function names read!")
86 f = open(outfile, 'w')
87 f.write(header % (outfile))
89 for fname in fnames:
90 ptr, name = get_api_tuple(fname)
91 # note: name no longer needed
92 f.write('#define %s \\\n\tgeany_functions->%s->%s\n' % (fname, ptr, fname))
94 f.write('\n#endif\n')
95 f.close()
97 if not '-q' in sys.argv:
98 sys.stdout.write('Generated %s\n' % outfile)