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 = {}
 
list sdk_conditionals = []
 
 split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
 

Function Documentation

◆ save_controller()

def sort_controllers.save_controller (   line)

Definition at line 17 of file sort_controllers.py.

17 def save_controller(line):
18  global controllers
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] == ""):
23  bindings.pop(0)
24  entry.extend(",".join(bindings) + ",")
25  entry.append(match.group(5))
26  controllers.append(entry)
27 
28  if ',sdk' in line:
29  sdk_conditionals.append(entry[1])
30 

Referenced by write_controllers().

◆ write_controllers()

def sort_controllers.write_controllers ( )

Definition at line 31 of file sort_controllers.py.

31 def write_controllers():
32  global controllers
33  global controller_guids
34  # Check for duplicates
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))
40 
41  if (not current_name.startswith("(DUPE)")):
42  entry[2] = "(DUPE) " + current_name
43 
44  if (not existing_name.startswith("(DUPE)")):
45  controller_guids[entry[1]][2] = "(DUPE) " + existing_name
46 
47  controller_guids[entry[1]] = entry
48 
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))
54  output.write(line)
55 
56  controllers = []
57  controller_guids = {}
58 

References save_controller().

Variable Documentation

◆ controller_guids

dictionary sort_controllers.controller_guids = {}

Definition at line 13 of file sort_controllers.py.

◆ controllers

list sort_controllers.controllers = []

Definition at line 12 of file sort_controllers.py.

Referenced by IOS_JoystickInit(), and SDL_GameControllerAddMappingsFromRW().

◆ 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.

◆ sdk_conditionals

list sort_controllers.sdk_conditionals = []

Definition at line 14 of file sort_controllers.py.

◆ split_pattern

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

Definition at line 15 of file sort_controllers.py.

sort_controllers.write_controllers
def write_controllers()
Definition: sort_controllers.py:31
sort_controllers.save_controller
def save_controller(line)
Definition: sort_controllers.py:17