1 # $Id: doxygen_filter.awk 23650 2011-12-21 14:30:08Z yexo $
3 # This file is part of OpenTTD.
4 # OpenTTD 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, version 2.
5 # OpenTTD 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.
6 # See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
9 # Awk script to automatically generate the code needed
10 # to export the script APIs to Squirrel.
12 # Note that arrays are 1 based...
21 skip_function_body =
"false"
25 if (apis ==
"gs") apis =
"game"
33 if (skip_function_body ==
"true") {
35 gsub(/[^
{]/, "", input
)
36 skip_function_par
+=
length(input
)
37 if (skip_function_par
> 0) {
39 gsub(/[^
}]/, "", input
)
40 skip_function_par
-=
length(input
)
41 if (skip_function_par ==
0) skip_function_body =
"false"
44 if (skip_function_body ==
"true") next
52 if (api ==
"Script") {
57 # By default, classes are not selected
58 if (cls_level ==
0) api_selected =
"false"
60 gsub("^([ ]*)", "", $
0)
61 gsub("* @api ", "", $
0)
64 api_selected =
"false"
65 } else if ($
0 ==
"-all") {
66 api_selected =
"false"
67 } else if (match($
0, "-" apis
)) {
68 api_selected =
"false"
69 } else if (match($
0, apis
)) {
76 # Ignore forward declarations of classes
77 /^
( *)class
(.
*);/ { next; }
78 # We only want to have public functions exported for now
81 if (api_selected ==
"") {
82 print "Class '"$
2"' has no @api. It won't be published to any API." > "/dev/stderr"
83 api_selected =
"false"
89 cls_in_api = api_selected
93 if (cls_in_api ==
"true") {
99 } else if (cls_level ==
1) {
100 if (api_selected ==
"") api_selected = cls_in_api
102 if (api_selected ==
"true") {
110 print "Classes nested too deep" > "/dev/stderr"
116 /^
( *)public
/ { if (cls_level ==
1) comment_buffer =
""; public =
"true"; next; }
117 /^
( *)protected
/ { if (cls_level ==
1) comment_buffer =
""; public =
"false"; next; }
118 /^
( *)private
/ { if (cls_level ==
1) comment_buffer =
""; public =
"false"; next; }
120 # Ignore special doxygen blocks
121 /^
#ifndef DOXYGEN_API/ { doxygen_skip = "true"; next; }
122 /^
#ifdef DOXYGEN_API/ { doxygen_skip = "next"; next; }
123 /^
#endif \/\* DOXYGEN_API \*\// { doxygen_skip = "false"; next; }
125 if (doxygen_skip ==
"next") {
126 doxygen_skip =
"true";
128 doxygen_skip =
"false";
132 { if (doxygen_skip ==
"true") next }
139 /\
/\
*\
*.
*\
*\
// { comment_buffer = $
0; comment =
"false"; next; }
140 /\
/\
*.
*\
*\
// { comment_buffer =
""; comment =
"false"; next; }
141 /\
/\
*\
*/ { comment_buffer = $
0 "\n"; comment =
"true"; next; }
142 /\
/\
*/ { comment_buffer =
""; comment =
"false"; next; }
143 /\
*\
// { comment_buffer = comment_buffer $
0; comment =
"false"; next; }
145 if (comment ==
"true" && !
match($
0, /@api
/))
147 if (match($
0, /@game
/) && api
!= "GS") next;
148 if (match($
0, /@ai
/) && api
!= "AI") next;
149 gsub("@game ", "", $
0);
150 gsub("@ai ", "", $
0);
151 comment_buffer = comment_buffer $
0 "\n"; next;
156 # We need to make specialized conversions for structs
158 comments_so_far = comment_buffer
162 # Check if we want to publish this struct
163 if (api_selected ==
"") api_selected = cls_in_api
164 if (api_selected ==
"false") {
170 if (public ==
"false") next
172 print comments_so_far
178 # We need to make specialized conversions for enums
180 comments_so_far = comment_buffer
184 # Check if we want to publish this enum
185 if (api_selected ==
"") api_selected = cls_in_api
186 if (api_selected ==
"false") {
192 if (public ==
"false") next
196 print comments_so_far
202 # Maybe the end of the class, if so we can start with the Squirrel export pretty soon
206 if (cls_level
!= 0) {
207 if (in_enum ==
"true") print
214 if (cls_in_api ==
"true") print
225 # Skip non-public functions
226 { if (public ==
"false") next }
230 if (in_enum ==
"true") {
233 gsub("=([^/]*),", ",", $
0)
236 # Check if this a special error enum
237 if (match(enums
[enum_size
], ".*::ErrorMessages") != 0) {
239 # enum ErrorMessages {
240 # ERR_SOME_ERROR, // [STR_ITEM1, STR_ITEM2, ...]
243 ##TODO: don't print the STR_*
249 # Add a const (non-enum) value
250 /^
[ ]*static const \w
+ \w
+ =
-?\
(?\w
*\
)?\w
+;/ {
251 if (api_selected ==
"") api_selected = cls_in_api
252 if (api_selected ==
"false") {
263 # Add a method to the list
265 if (cls_level
!= 1) next
266 if (!
match($
0, ";")) {
268 skip_function_body =
"true"
270 if (match($
0, "~")) {
271 if (api_selected
!= "") {
272 print "Destructor for '"cls
"' has @api. Tag ignored." > "/dev/stderr"
278 # Check if we want to publish this function
279 if (api_selected ==
"") api_selected = cls_in_api
280 if (api_selected ==
"false") {