-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.py
128 lines (103 loc) · 4.33 KB
/
generate.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
config_file = "src/includedb_config.h"
files = [
("src/includedb_core.h" , [ ]),
("src/includedb_bloom.c" , ["src/includedb_config.h"]),
("src/includedb_bitvec.c" , ["src/includedb_config.h"]),
("src/includedb_skiplist.c", ["src/includedb_config.h"]),
("src/includedb_fileops.c" , ["src/includedb_config.h"]),
("src/includedb_core.c" , ["src/includedb_config.h"])
]
# for testing only:
mix = [
("g", ["d","f","e"]),
("a", []),
("f", ["b","c"]),
("b", []),
("c", []),
("d", ["e","c"]),
("e", ["a","b"])
]
def filter(i,sources):
new = []
for elem in sources:
if elem[0]==i:
new.append(elem)
return new
def extr(tup, sources):
new = []
for i in tup[1]:
new += filter(i, sources)
return new
def arrange(sources):
new = []
for elem in reversed(sources):
new += extr(elem, sources)
return new
sorted = arrange(files) + files
unique = []
[unique.append(elem) for elem in sorted if elem not in unique]
for c in unique:
print(c[0]+" - "+" ".join(c[1]))
merge_result = """/*
You need to add '#define INCLUDEDB_IMPLEMENTATION' before including this header in ONE source file.
Like this:
#define INCLUDEDB_IMPLEMENTATION
#include \"includedb.h\"
To disable compile-time unit tests:
#define DISABLE_TESTS
AUTHOR
Professor Peanut
LICENSE
MIT - See end of file.
HISTORY
While in alpha cross version compatibility is not guaranteed. Do not replace
this file if you need to keep your database readable.
0.1.1 Splitting into multiple files, use generator.py to create single-header!
0.1.0 Initial release
PEANUTS
SPONSORS: https://github.com/sponsors/Professor-Peanut
BUYMEACOFFEE: https://www.buymeacoffe.com/professorPeanut
LIGHTNING: lnbc169690n1pj2jm89pp5wxlx47arg3nu2sajfdu5uq3u2dgs0d5hvzhv60rv5lzu8h5h4z5qdqu2askcmr9wssx7e3q2dshgmmndp5scqzzsxqyz5vqsp52m4d5w2gwauz4nhn4jypempvq4wuxef7unvzgmfppggwpdpn5j3s9qyyssqveag435teq0uhfp4mgzxp8p2q534kans7ns4sgegvq5qrg628djjk4s3jnmu72d5wvnclm03ts5u883jv6jvqnj9847sk03yplj9thspdgp6v3
BTC: bc1qpv63qlpec3x3lh2cejmr5audh2c6j2ar3ptvy235hld3f2wwzr5sg4qr5n
BCH: qzfy6xcw93s8605rywcwug3vpf5kmy5ywgw0lw5lj0
LTC: LPM7ueXta6kFwCnBKd5viJDX2CN8eLsg3b
XMR: 47NF2hjeMXMMCHu6XNyMrWeJwkndaTNvGAKAQuy6v9wvNTHViVwi3BGTr8wy9U4aoNbDcLMEf7dVjNGvQacttGc3CjEJgP8
Let's cook this panutsoup together!!!
*/\n\n"""
license = """/*
------------------------------------------------------------------------------
Copyright (c) 2023 Professor Peanut
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
This copyright notice and permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
*/
"""
merge_result += "#ifndef INCLUDEDB_DB_H\n#define INCLUDEDB_DB_H\n\n"
merge_result += open(config_file, "r").read()
merge_result += "\n\n#ifdef INCLUDEDB_IMPLEMENTATION\n\n\n"
for filename in unique:
if filename[0] != config_file:
f = open(filename[0], "r")
lines = f.readlines()
for code_line in lines:
if code_line.startswith("#include \"") == False:
merge_result += code_line
merge_result += "\n\n"
merge_result += "#endif // INCLUDEDB_IMPLEMENTATION\n\n\n#endif // INCLUDEDB_DB_H\n"
merge_result+= license
open("./includedb.h", "w+").write(merge_result + "\n")
print("success")