forked from geany/geany
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenapi.py
More file actions
executable file
·94 lines (78 loc) · 2.86 KB
/
Copy pathgenapi.py
File metadata and controls
executable file
·94 lines (78 loc) · 2.86 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# genapi.py - this file is part of Geany, a fast and lightweight IDE
#
# Copyright 2008-2011 Nick Treleaven <nick.treleaven<at>btinternet.com>
# Copyright 2008-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# $(Id)
r"""
Creates macros for each plugin API function pointer, e.g.:
#define plugin_add_toolbar_item \
geany_functions->p_plugin->plugin_add_toolbar_item
"""
import re, sys
def get_function_names():
names = []
filep = open('../src/plugins.c')
while 1:
line = filep.readline()
if line == "":
break
match = re.match("^\t&([a-z][a-z0-9_]+)", line)
if match:
symbol = match.group(1)
if not symbol.endswith('_funcs'):
names.append(symbol)
filep.close()
return names
def get_api_tuple(source):
match = re.match("^([a-z]+)_([a-z][a-z0-9_]+)$", source)
return 'p_' + match.group(1), match.group(2)
header = \
r'''/* This file is generated automatically by genapi.py - do not edit. */
/** @file %s @ref geany_functions wrappers.
* This allows the use of normal API function names in plugins by defining macros.
*
* E.g.:@code
* #define plugin_add_toolbar_item \
* geany_functions->p_plugin->plugin_add_toolbar_item @endcode
*
* You need to declare the @ref geany_functions symbol yourself.
*
* Note: This must be included after all other API headers to prevent conflicts with
* other header's function prototypes - this is done for you when using geanyplugin.h.
*/
#ifndef GEANY_FUNCTIONS_H
#define GEANY_FUNCTIONS_H
'''
if __name__ == "__main__":
outfile = 'geanyfunctions.h'
fnames = get_function_names()
if not fnames:
sys.exit("No function names read!")
f = open(outfile, 'w')
print >> f, header % (outfile)
for fname in fnames:
ptr, name = get_api_tuple(fname)
# note: name no longer needed
print >> f, '#define %s \\\n\tgeany_functions->%s->%s' % (fname, ptr, fname)
print >> f, '\n#endif'
f.close()
if not '-q' in sys.argv:
print 'Generated ' + outfile