mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 04:36:07 +00:00
aux/bindings: Refactor path verify function generation
This commit is contained in:
parent
037c49ce30
commit
a8c254a8cf
|
@ -174,7 +174,7 @@ class Profile:
|
||||||
collector = PathsByLengthCollector()
|
collector = PathsByLengthCollector()
|
||||||
for component in self.components:
|
for component in self.components:
|
||||||
collector.add_paths(component.get_full_openxr_paths())
|
collector.add_paths(component.get_full_openxr_paths())
|
||||||
self.by_length = collector.to_dict_of_lists()
|
self.subpaths_by_length = collector.to_dict_of_lists()
|
||||||
|
|
||||||
|
|
||||||
class Bindings:
|
class Bindings:
|
||||||
|
@ -211,7 +211,7 @@ header = '''// Copyright 2020-2022, Collabora, Ltd.
|
||||||
|
|
||||||
func_start = '''
|
func_start = '''
|
||||||
bool
|
bool
|
||||||
oxr_verify_{func}_subpath(const char *str, size_t length)
|
{name}(const char *str, size_t length)
|
||||||
{{
|
{{
|
||||||
\tswitch (length) {{
|
\tswitch (length) {{
|
||||||
'''
|
'''
|
||||||
|
@ -221,6 +221,20 @@ if_strcmp = '''if (strcmp(str, "{check}") == 0) {{
|
||||||
\t\t}} else '''
|
\t\t}} else '''
|
||||||
|
|
||||||
|
|
||||||
|
def write_verify_func(f, name, dict_of_lists):
|
||||||
|
"""Generate function to check if a string is in a set of strings.
|
||||||
|
Input is a file to write the code into, a dict where keys are length and
|
||||||
|
the values are lists of strings of that length. And a suffix if any."""
|
||||||
|
|
||||||
|
f.write(func_start.format(name=name))
|
||||||
|
for length in dict_of_lists:
|
||||||
|
f.write("\tcase " + str(length) + ":\n\t\t")
|
||||||
|
for path in dict_of_lists[length]:
|
||||||
|
f.write(if_strcmp.format(check=path))
|
||||||
|
f.write("{\n\t\t\treturn false;\n\t\t}\n")
|
||||||
|
f.write("\tdefault:\n\t\treturn false;\n\t}\n}\n")
|
||||||
|
|
||||||
|
|
||||||
def generate_bindings_c(file, p):
|
def generate_bindings_c(file, p):
|
||||||
"""Generate the file to verify subpaths on a interaction profile."""
|
"""Generate the file to verify subpaths on a interaction profile."""
|
||||||
f = open(file, "w")
|
f = open(file, "w")
|
||||||
|
@ -233,13 +247,8 @@ def generate_bindings_c(file, p):
|
||||||
''')
|
''')
|
||||||
|
|
||||||
for profile in p.profiles:
|
for profile in p.profiles:
|
||||||
f.write(func_start.format(func=profile.validation_func_name))
|
name = "oxr_verify_" + profile.validation_func_name + "_subpath"
|
||||||
for length in profile.by_length:
|
write_verify_func(f, name, profile.subpaths_by_length)
|
||||||
f.write("\tcase " + str(length) + ":\n\t\t")
|
|
||||||
for path in profile.by_length[length]:
|
|
||||||
f.write(if_strcmp.format(check=path))
|
|
||||||
f.write("{\n\t\t\treturn false;\n\t\t}\n")
|
|
||||||
f.write("\tdefault:\n\t\treturn false;\n\t}\n}\n")
|
|
||||||
|
|
||||||
f.write(
|
f.write(
|
||||||
f'\n\nstruct profile_template profile_templates[{len(p.profiles)}] = {{ // array of profile_template\n')
|
f'\n\nstruct profile_template profile_templates[{len(p.profiles)}] = {{ // array of profile_template\n')
|
||||||
|
|
Loading…
Reference in a new issue