linux-qubasis

linux oasis port as a qubes template

git clone https://9o.is/git/linux-qubasis.git

eventnames.lua

(3421B)


      1 local duplicates = {
      2 	EV_VERSION=true,
      3 	BTN_MISC=true,
      4 	BTN_MOUSE=true,
      5 	BTN_JOYSTICK=true,
      6 	BTN_GAMEPAD=true,
      7 	BTN_DIGI=true,
      8 	BTN_WHEEL=true,
      9 	BTN_TRIGGER_HAPPY=true,
     10 	SW_MAX=true,
     11 	REP_MAX=true,
     12 	FF_STATUS_MAX=true,
     13 }
     14 
     15 local skip = {
     16 	BTN=true,
     17 	EV=true,
     18 	INPUT_PROP=true,
     19 	MT_TOOL=true,
     20 }
     21 
     22 local prefixes = {
     23 	'EV',
     24 	'REL',
     25 	'ABS',
     26 	'KEY',
     27 	'BTN',
     28 	'LED',
     29 	'SND',
     30 	'MSC',
     31 	'SW',
     32 	'FF',
     33 	'SYN',
     34 	'REP',
     35 	'INPUT_PROP',
     36 	'MT_TOOL',
     37 }
     38 
     39 local bits = {}
     40 for _, prefix in ipairs(prefixes) do
     41 	bits[prefix] = {}
     42 end
     43 bits.EV.map = {}
     44 
     45 local function lookuptable(prefix)
     46 	local entries = {}
     47 	for _, name in ipairs(bits[prefix]) do
     48 		table.insert(entries, name)
     49 	end
     50 	local max = prefix..'_MAX'
     51 	if duplicates[max] then
     52 		table.insert(entries, max)
     53 	end
     54 	table.sort(entries)
     55 	for _, name in ipairs(entries) do
     56 		io.write(string.format('    { .name = "%s", .value = %s },\n', name, name))
     57 	end
     58 end
     59 
     60 for i = 1, #arg do
     61 	for line in io.lines(arg[i]) do
     62 		local name, value = line:match('^#define%s+([%w_]+)%s+(%dx?%x*)')
     63 		value = tonumber(value)
     64 		if name and not duplicates[name] then
     65 			for prefix, b in pairs(bits) do
     66 				if name:sub(1, #prefix + 1) == prefix..'_' then
     67 					if b.map then
     68 						b.map[value] = name
     69 						b.map[name] = value
     70 					end
     71 					table.insert(b, name)
     72 				end
     73 			end
     74 		end
     75 	end
     76 end
     77 
     78 io.write[[
     79 /* THIS FILE IS GENERATED, DO NOT EDIT */
     80 
     81 #ifndef EVENT_NAMES_H
     82 #define EVENT_NAMES_H
     83 
     84 ]]
     85 for _, prefix in ipairs(prefixes) do
     86 	if prefix ~= 'BTN' then
     87 		io.write(string.format('static const char * const %s_map[%s_MAX + 1] = {\n', prefix:lower(), prefix))
     88 		for _, name in ipairs(bits[prefix]) do
     89 			io.write(string.format('    [%s] = "%s",\n', name, name))
     90 		end
     91 		if prefix == 'KEY' then
     92 			for _, name in ipairs(bits.BTN) do
     93 				io.write(string.format('    [%s] = "%s",\n', name, name))
     94 			end
     95 		end
     96 		io.write[[
     97 };
     98 
     99 ]]
    100 	end
    101 end
    102 for _, name in ipairs{'BTN_A', 'BTN_B', 'BTN_X', 'BTN_Y'} do
    103 	table.insert(bits.BTN, name)
    104 end
    105 io.write[[
    106 static const char * const * const event_type_map[EV_MAX + 1] = {
    107 ]]
    108 for _, prefix in ipairs(prefixes) do
    109 	if not skip[prefix] then
    110 		print(string.format('    [EV_%s] = %s_map,', prefix, prefix:lower()))
    111 	end
    112 end
    113 io.write[[
    114 };
    115 
    116 #if __clang__
    117 #pragma clang diagnostic push
    118 #pragma clang diagnostic ignored "-Winitializer-overrides"
    119 #elif __GNUC__
    120 #pragma GCC diagnostic push
    121 #pragma GCC diagnostic ignored "-Woverride-init"
    122 #endif
    123 static const int ev_max[EV_MAX + 1] = {
    124 ]]
    125 for i = 0, bits.EV.map.EV_MAX do
    126 	local name = bits.EV.map[i]
    127 	if name and bits[name:sub(4)] then
    128 		io.write(string.format('    %s_MAX,\n', name:sub(4)))
    129 	else
    130 		io.write('    -1,\n')
    131 	end
    132 end
    133 io.write[[
    134 };
    135 #if __clang__
    136 #pragma clang diagnostic pop /* "-Winitializer-overrides" */
    137 #elif __GNUC__
    138 #pragma GCC diagnostic pop /* "-Woverride-init" */
    139 #endif
    140 
    141 struct name_entry {
    142     const char *name;
    143     unsigned int value;
    144 };
    145 
    146 static const struct name_entry tool_type_names[] = {
    147 ]]
    148 lookuptable('MT_TOOL')
    149 io.write[[
    150 };
    151 
    152 static const struct name_entry ev_names[] = {
    153 ]]
    154 lookuptable('EV')
    155 io.write[[
    156 };
    157 
    158 static const struct name_entry code_names[] = {
    159 ]]
    160 lookuptable('ABS')
    161 lookuptable('BTN')
    162 lookuptable('FF')
    163 lookuptable('KEY')
    164 lookuptable('LED')
    165 lookuptable('MSC')
    166 lookuptable('REL')
    167 lookuptable('REP')
    168 lookuptable('SND')
    169 lookuptable('SW')
    170 lookuptable('SYN')
    171 io.write[[
    172 };
    173 
    174 static const struct name_entry prop_names[] = {
    175 ]]
    176 lookuptable('INPUT_PROP')
    177 io.write[[
    178 };
    179 
    180 #endif /* EVENT_NAMES_H */
    181 ]]