8 filename =
"SDL_gamecontrollerdb.h"
10 output = open(filename +
".new",
"w")
11 parsing_controllers =
False
15 split_pattern = re.compile(
r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
19 match = split_pattern.match(line)
20 entry = [ match.group(1), match.group(2), match.group(3) ]
21 bindings = sorted(match.group(4).split(
","))
22 if (bindings[0] ==
""):
24 entry.extend(
",".join(bindings) +
",")
25 entry.append(match.group(5))
26 controllers.append(entry)
29 sdk_conditionals.append(entry[1])
33 global controller_guids
35 for entry
in controllers:
36 if (entry[1]
in controller_guids
and entry[1]
not in sdk_conditionals):
37 current_name = entry[2]
38 existing_name = controller_guids[entry[1]][2]
39 print(
"Warning: entry '%s' is duplicate of entry '%s'" % (current_name, existing_name))
41 if (
not current_name.startswith(
"(DUPE)")):
42 entry[2] =
"(DUPE) " + current_name
44 if (
not existing_name.startswith(
"(DUPE)")):
45 controller_guids[entry[1]][2] =
"(DUPE) " + existing_name
47 controller_guids[entry[1]] = entry
49 for entry
in sorted(controllers, key=
lambda entry: entry[2]+
"-"+entry[1]):
50 line =
"".join(entry) +
"\n"
51 line = line.replace(
"\t",
" ")
52 if not line.endswith(
",\n")
and not line.endswith(
"*/\n"):
53 print(
"Warning: '%s' is missing a comma at the end of the line" % (line))
60 if (parsing_controllers):
61 if (line.startswith(
"{")):
63 elif (line.startswith(
" NULL")):
64 parsing_controllers =
False
67 elif (line.startswith(
"#if")):
68 print(
"Parsing " + line.strip())
70 elif (line.startswith(
"#endif")):
76 if (line.startswith(
"static const char *s_ControllerMappings")):
77 parsing_controllers =
True
82 print(
"Finished writing %s.new" % filename)