SDL  2.0
sort_controllers Namespace Reference

Functions

def find_element (prefix, bindings)
 
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 conditionals = []
 
 split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
 

Function Documentation

◆ find_element()

def sort_controllers.find_element (   prefix,
  bindings 
)

Definition at line 17 of file sort_controllers.py.

17 def find_element(prefix, bindings):
18  i=0
19  for element in bindings:
20  if element.startswith(prefix):
21  return i
22  i=(i + 1)
23 
24  return -1
25 
def find_element(prefix, bindings)

Referenced by save_controller().

◆ save_controller()

def sort_controllers.save_controller (   line)

Definition at line 26 of file sort_controllers.py.

26 def save_controller(line):
27  global controllers
28  match = split_pattern.match(line)
29  entry = [ match.group(1), match.group(2), match.group(3) ]
30  bindings = sorted(match.group(4).split(","))
31  if (bindings[0] == ""):
32  bindings.pop(0)
33 
34  pos=find_element("sdk", bindings)
35  if pos >= 0:
36  bindings.append(bindings.pop(pos))
37 
38  pos=find_element("hint:", bindings)
39  if pos >= 0:
40  bindings.append(bindings.pop(pos))
41 
42  entry.extend(",".join(bindings) + ",")
43  entry.append(match.group(5))
44  controllers.append(entry)
45 
46  if ',sdk' in line or ',hint:' in line:
47  conditionals.append(entry[1])
48 
def save_controller(line)

References find_element().

Referenced by write_controllers().

◆ write_controllers()

def sort_controllers.write_controllers ( )

Definition at line 49 of file sort_controllers.py.

49 def write_controllers():
50  global controllers
51  global controller_guids
52  # Check for duplicates
53  for entry in controllers:
54  if (entry[1] in controller_guids and entry[1] not in conditionals):
55  current_name = entry[2]
56  existing_name = controller_guids[entry[1]][2]
57  print("Warning: entry '%s' is duplicate of entry '%s'" % (current_name, existing_name))
58 
59  if (not current_name.startswith("(DUPE)")):
60  entry[2] = "(DUPE) " + current_name
61 
62  if (not existing_name.startswith("(DUPE)")):
63  controller_guids[entry[1]][2] = "(DUPE) " + existing_name
64 
65  controller_guids[entry[1]] = entry
66 
67  for entry in sorted(controllers, key=lambda entry: entry[2]+"-"+entry[1]):
68  line = "".join(entry) + "\n"
69  line = line.replace("\t", " ")
70  if not line.endswith(",\n") and not line.endswith("*/\n"):
71  print("Warning: '%s' is missing a comma at the end of the line" % (line))
72  output.write(line)
73 
74  controllers = []
75  controller_guids = {}
76 

References save_controller().

Variable Documentation

◆ conditionals

list sort_controllers.conditionals = []

Definition at line 14 of file sort_controllers.py.

◆ 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 15 of file sort_controllers.py.