8 filename =
"SDL_gamecontrollerdb.h"
10 output = open(filename +
".new",
"w")
11 parsing_controllers =
False
14 split_pattern = re.compile(
r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
18 match = split_pattern.match(line)
19 entry = [ match.group(1), match.group(2), match.group(3) ]
20 bindings = sorted(match.group(4).split(
","))
21 if (bindings[0] ==
""):
23 entry.extend(
",".join(bindings) +
",")
24 entry.append(match.group(5))
25 controllers.append(entry)
29 global controller_guids
30 for entry
in sorted(controllers, key=
lambda entry: entry[2]):
31 line =
"".join(entry) +
"\n"
32 if (entry[1]
in controller_guids):
33 print "Warning: entry '%s' is duplicate of entry '%s'" % (entry[2], controller_guids[entry[1]][2])
34 controller_guids[entry[1]] = entry
41 if ( parsing_controllers ):
42 if (line.startswith(
"{")):
44 elif (line.startswith(
"#endif")):
45 parsing_controllers =
False
48 elif (line.startswith(
"#")):
49 print "Parsing " + line.strip()
55 if (line.startswith(
"static const char *s_ControllerMappings")):
56 parsing_controllers =
True
61 print "Finished writing %s.new" % filename