SDL 2.0
sort_controllers Namespace Reference

Functions

def save_controller (line)
 
def write_controllers ()
 

Variables

string filename = "SDL_gamecontrollerdb.h"
 
 input = open(filename)
 
 output = open(filename + ".new", "w")
 
bool parsing_controllers = False
 
list controllers = []
 
dictionary controller_guids = {}
 
 split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
 

Function Documentation

◆ save_controller()

def sort_controllers.save_controller (   line)

Definition at line 16 of file sort_controllers.py.

16def save_controller(line):
17 global controllers
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] == ""):
22 bindings.pop(0)
23 entry.extend(",".join(bindings) + ",")
24 entry.append(match.group(5))
25 controllers.append(entry)
26
def save_controller(line)

Referenced by write_controllers().

◆ write_controllers()

def sort_controllers.write_controllers ( )

Definition at line 27 of file sort_controllers.py.

28 global controllers
29 global controller_guids
30 # Check for duplicates
31 for entry in controllers:
32 if (entry[1] in controller_guids):
33 current_name = entry[2]
34 existing_name = controller_guids[entry[1]][2]
35 print("Warning: entry '%s' is duplicate of entry '%s'" % (current_name, existing_name))
36
37 if (not current_name.startswith("(DUPE)")):
38 entry[2] = "(DUPE) " + current_name
39
40 if (not existing_name.startswith("(DUPE)")):
41 controller_guids[entry[1]][2] = "(DUPE) " + existing_name
42
43 controller_guids[entry[1]] = entry
44
45 for entry in sorted(controllers, key=lambda entry: entry[2]+"-"+entry[1]):
46 line = "".join(entry) + "\n"
47 line = line.replace("\t", " ")
48 if not line.endswith(",\n") and not line.endswith("*/\n"):
49 print("Warning: '%s' is missing a comma at the end of the line" % (line))
50 output.write(line)
51
52 controllers = []
53 controller_guids = {}
54

References save_controller(), and write_controllers().

Referenced by write_controllers().

Variable Documentation

◆ controller_guids

dictionary sort_controllers.controller_guids = {}

Definition at line 13 of file sort_controllers.py.

◆ controllers

list sort_controllers.controllers = []

◆ filename

string sort_controllers.filename = "SDL_gamecontrollerdb.h"

Definition at line 8 of file sort_controllers.py.

Referenced by _AssertFileExist(), and main().

◆ input

sort_controllers.input = open(filename)

Definition at line 9 of file sort_controllers.py.

◆ output

◆ parsing_controllers

bool sort_controllers.parsing_controllers = False

Definition at line 11 of file sort_controllers.py.

◆ split_pattern

sort_controllers.split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')

Definition at line 14 of file sort_controllers.py.