Fix some daylength issues, possible division by zero in main menu.
[openttd-joker.git] / src / script / api / generate_widget.awk
blob1e2da61f9b6889d777cab9359581d9d250903efc
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.
13 # Example:
14 # // @enum enumname filename
15 # ... content here is replaced ...
16 # // @endenum
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.
23 BEGIN {
24 skiptillend = 0;
27 /@enum/ {
28 print;
29 add_indent = gensub("[^ ]*", "", "g");
30 sub(".*@enum *", "");
31 enum = $1;
32 pattern = $2;
34 files = "echo " pattern;
35 files | getline filelist;
36 close(files);
38 split(filelist, filearray);
39 count = asort(filearray);
40 for (i = 1; i <= count; i++) {
41 active = 0;
42 active_comment = 0;
43 comment = "";
44 file = filearray[i];
45 print add_indent "/* automatically generated from " file " */"
46 while ((getline < file) > 0) {
47 sub(rm_indent, "");
49 # Remember possible doxygen comment before enum declaration
50 if ((active == 0) && (match($0, "/\\*\\*") > 0)) {
51 comment = add_indent $0;
52 active_comment = 1;
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) {
59 rm_indent = $0;
60 gsub("[^ ]*", "", rm_indent);
61 active = 1;
62 if (active_comment > 0) print comment;
63 active_comment = 0;
64 comment = "";
67 # Forget doxygen comment, if no enum follows
68 if (active_comment == 2 && $0 != "") {
69 active_comment = 0;
70 comment = "";
72 if (active_comment == 1 && match($0, "\\*/") > 0) active_comment = 2;
74 if (active != 0) {
75 if (match($0, "^ *[A-Za-z0-9_]* *[,=]") > 0) {
76 # Transform enum values
77 sub(" *=[^,]*", "");
78 sub(" *//", " //");
80 match($0, "^( *)([A-Za-z0-9_]+),(.*)", parts);
81 enumwidth - length(parts[2])
83 if (parts[3] == "") {
84 printf "%s%s%-45s= ::%s\n", add_indent, parts[1], parts[2], (parts[2] ",")
85 } else {
86 printf "%s%s%-45s= ::%-45s%s\n", add_indent, parts[1], parts[2], (parts[2] ","), parts[3];
88 } else if ($0 == "") {
89 print "";
90 } else {
91 print add_indent $0;
95 if (match($0, "^ *\\};") > 0) {
96 if (active != 0) print "";
97 active = 0;
100 close(file);
103 skiptillend = 1;
104 next;
107 /@endenum/ {
108 print;
109 skiptillend = 0;
110 next;
114 if (skiptillend == 0) print;