forked from petabyt/camlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringify.py
42 lines (36 loc) · 1.26 KB
/
stringify.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
# Quick python script to scan and dump PTP codes
import re
PTP_DEV_EMPTY = 0
PTP_DEV_EOS = 1
PTP_DEV_CANON = 2
PTP_DEV_NIKON = 3
PTP_DEV_SONY = 4
PTP_DEV_FUJI = 5
PTP_DEV_PANASONIC = 6
output = "// autogenerated file\n#include <cl_enum.h>\nstruct PtpEnum ptp_enums[] = {\n"
string = open("src/ptp.h", "r").read()
regex = r"#define ([A-Za-z0-9_]+)[ \t]+(0x[0-9a-fA-Z]+)"
matches = re.findall(regex, string)
for i in matches:
t = re.findall(r"PTP_(OC|PC|OF|EC|RC|PC|ST|FT|AC)_(CANON|FUJI|NIKON|SONY|EOS|)[_]?([A-Za-z0-9_]+)", i[0])
if len(t) == 0:
output += "{PTP_ENUM, 0, \"" + i[0] + "\", " + i[1] + "},\n"
else:
vendor = t[0][1]
if vendor == "":
vendor = str(PTP_DEV_EMPTY)
elif vendor == "CANON":
vendor = str(PTP_DEV_CANON)
elif vendor == "EOS":
vendor = str(PTP_DEV_EOS)
elif vendor == "NIKON":
vendor = str(PTP_DEV_NIKON)
elif vendor == "FUJI":
vendor = str(PTP_DEV_FUJI)
output += "{PTP_" + t[0][0] + ", " + vendor + ", " + "\"" + i[0] + "\", " + i[1] + "},\n"
output += "\n};"
output += "int ptp_enums_length = " + str(len(matches)) + ";\n"
print("Compiled", len(matches), "enums")
f = open("src/enum_dump.c", "w")
f.write(output)
f.close()