1 # $Id: generate_widget.awk 24664 2012-11-05 19:53:05Z frosch $
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 enums in script_window.hpp
11 # The file is scanned for @enum and @endenum tokens, and the content between them is replaced by an enum from a different file.
14 # // @enum enumname filename
15 # ... content here is replaced ...
18 # The parameter "enumname" specifies the enumeration to extract. This can also be a regular expression.
19 # The parameter "filename" specifies the relative path to the file, where the enumeration is extracted from. This can also be a glob expression.
29 add_indent = gensub
("[^ ]*", "", "g");
34 files =
"echo " pattern
;
35 files
| getline filelist
;
38 split(filelist
, filearray
);
39 count = asort
(filearray
);
40 for (i =
1; i
<= count
; i
++) {
45 print add_indent
"/* automatically generated from " file
" */"
46 while ((getline < file
) > 0) {
49 # Remember possible doxygen comment before enum declaration
50 if ((active ==
0) && (match($
0, "/\\*\\*") > 0)) {
51 comment = add_indent $
0;
53 } else if (active_comment ==
1) {
54 comment = comment
"\n" add_indent $
0;
57 # Check for enum match
58 if (match($
0, "^ *enum *" enum
" *\\{") > 0) {
60 gsub("[^ ]*", "", rm_indent
);
62 if (active_comment
> 0) print comment
;
67 # Forget doxygen comment, if no enum follows
68 if (active_comment ==
2 && $
0 != "") {
72 if (active_comment ==
1 && match($
0, "\\*/") > 0) active_comment =
2;
75 if (match($
0, "^ *[A-Za-z0-9_]* *[,=]") > 0) {
76 # Transform enum values
80 match($
0, "^( *)([A-Za-z0-9_]+),(.*)", parts
);
81 enumwidth
- length(parts
[2])
84 printf "%s%s%-45s= ::%s\n", add_indent
, parts
[1], parts
[2], (parts
[2] ",")
86 printf "%s%s%-45s= ::%-45s%s\n", add_indent
, parts
[1], parts
[2], (parts
[2] ","), parts
[3];
88 } else if ($
0 ==
"") {
95 if (match($
0, "^ *\\};") > 0) {
96 if (active
!= 0) print "";
114 if (skiptillend ==
0) print;