input-eventd: gen: add count information to the index
authorBenoît Canet <benoit.canet@gmail.com>
Fri, 10 Jun 2011 22:46:30 +0000 (00:46 +0200)
committerBenoît Canet <benoit.canet@gmail.com>
Fri, 10 Jun 2011 23:01:00 +0000 (01:01 +0200)
input-eventd/gen/gen.py
input-eventd/gen/tests.py

index c3a6d66..3ec668f 100644 (file)
@@ -71,19 +71,21 @@ def generate_index_struct():
        return """
 struct index_entry {
        uint16_t type;
+       uint16_t count;
        struct input_entry *codes;
 };
 
 """
 
-def generate_index(types, not_empty):
+def generate_index(types, not_empty, codes_count):
        result = "struct index_entry table_index[] = {\n"
 
        for key in types:
                value = types[key][3:]
                if value in not_empty:
                        value = "codes_"+ value.lower()
-                       result += "\t{.type = %s, .codes = %s},\n" % (key, value)
+                       result += "\t{.type = %s, .codes = %s, .count = %i},\n" % \
+                                        (key, value, codes_count[value])
 
        result += "\t{}"
        result += "\n};\n\n"
@@ -99,13 +101,16 @@ def generate(filename):
        result += generate_table("event_types", types)
 
        not_empty_types = []
+       codes_count = {}
        for t in get_event_type_list(types):
                codes = parse_file_by_prefix(filename, t+"_")
                if len(codes):
-                       result += generate_table("codes_"+t.lower(), codes)
+                       table_name = "codes_"+t.lower()
+                       result += generate_table(table_name, codes)
                        not_empty_types.append(t)
+                       codes_count[table_name] = len(codes)
 
-       result += generate_index(types, not_empty_types)
+       result += generate_index(types, not_empty_types, codes_count)
        result += generate_footer()
 
        return result
index b738952..2b9edb7 100644 (file)
@@ -92,10 +92,11 @@ class TestSuite(unittest.TestCase):
                test_array = { '0x69' : "EV_TEST",
                               '0x70' : "EV_TAISTE" }
                test_list  = [ "TEST" ]
+               codes_count = { "codes_test" : 2}
 
-               result = generate_index(test_array, test_list)
+               result = generate_index(test_array, test_list, codes_count)
                test_string = """struct index_entry table_index[] = {
-       {.type = 0x69, .codes = codes_test},
+       {.type = 0x69, .codes = codes_test, .count = 2},
        {}
 };