aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/lz4/generated/gen.py
blob: 24dec0555c25b7d1a1f6aa626e34ca164708a5e4 (plain) (blame)
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
import os

lz4 = '''
#define LZ4_MEMORY_USAGE {i}
#define LZ4_NAMESPACE lz4_{i}
#include "lz4_ns.h"
'''.lstrip()

lz4methods = '''
#include "iface.h"

%s

extern "C" {

struct TLZ4Methods* LZ4Methods(int memory) {
    switch (memory) {
%s
    }

    return 0;
}

}
'''.lstrip()

lz4_namespace = 'namespace lz4_{i} {{ extern struct TLZ4Methods ytbl; }}'
lz4_case = '        case {i}: return &lz4_{i}::ytbl;'

namespaces = []
cases = []

os.chdir(os.path.dirname(__file__))

for i in range(10, 21):
    name = 'lz4_{}.cpp'.format(i)
    namespaces.append(lz4_namespace.format(i=i))
    cases.append(lz4_case.format(i=i))
    print '    ' + name

    with open(name, 'w') as f:
        f.write(lz4.format(i=i))

with open('lz4methods.cpp', 'w') as f:
    f.write(lz4methods % ('\n'.join(namespaces), '\n'.join(cases)))