forked from rpetrich/iphoneheaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateAvailability2.d
80 lines (66 loc) · 2.39 KB
/
GenerateAvailability2.d
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
/*
GenerateAvailability2.d ... Generate <Availability2.h>
Copyright (C) 2009 KennyTM~ <[email protected]>
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 3 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, see <http://www.gnu.org/licenses/>.
*/
import std.stdio;
import std.algorithm;
import std.string;
import std.array;
import std.conv;
int versToInt(string vers) {
auto s = vers.split(".");
auto major = to!int(s[0]), minor = to!int(s[1]);
return major * 10000 + minor * 100;
}
void main (string[] argv) {
if (argv.length == 1) {
writeln("Usage: GenerateAvailability2 2.0 2.1 2.2 3.0 3.1 4.0 ...");
} else {
auto args = argv[1..$];
sort(args);
auto vers = map!(`"__IPHONE_" ~ replace(a, ".", "_")`, versToInt)(args);
writeln("#ifndef AVAILABILITY2_H\n#define AVAILABILITY2_H\n#include <Availability.h>\n");
auto isFirst2 = true;
foreach (v; vers) {
if (isFirst2) {
isFirst2 = false;
continue;
}
auto vs = v.field[0];
writeln("#ifndef ", vs);
writeln(" #define ", vs, " ", v.field[1]);
writeln(" #define __AVAILABILITY_INTERNAL", vs, " __AVAILABILITY_INTERNAL_UNAVAILABLE");
writeln(" #define __AVAILABILITY_INTERNAL", vs, "_DEP__IPHONE_NA __AVAILABILITY_INTERNAL", vs);
auto isElsif = false, isFirst = true;
foreach (v2; vers) {
if (isFirst) {
isFirst = false;
continue;
}
auto v2s = v2.field[0];
writeln(isElsif?" #elif":" #if", " __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE", v2s);
isElsif = true;
foreach (v3; vers)
writeln(" #define __AVAILABILITY_INTERNAL", v3.field[0], "_DEP", vs, v3.field[1] < v2.field[1] ? "" : " __AVAILABILITY_INTERNAL_WEAK_IMPORT");
if (v.field[1] <= v2.field[1])
break;
}
writeln(" #else");
foreach (v3; vers)
writeln(" #define __AVAILABILITY_INTERNAL", v3.field[0], "_DEP", vs, " __AVAILABILITY_INTERNAL_DEPRECATED");
writeln(" #endif");
writeln("#endif");
}
writeln("\n#endif");
}
}