static void input_state_set_last(unsigned port, unsigned device, unsigned index, unsigned id, int16_t value) { unsigned i; InputListElement *element = NULL; const unsigned MAX_ID = sizeof(element->state) / sizeof(int16_t); if (!input_state_list) mylist_create(&input_state_list, 16, InputListElementConstructor, free); /* find list item */ for (i = 0; i < (unsigned)input_state_list->size; i++) { element = (InputListElement*)input_state_list->data[i]; if ( (element->port == port) && (element->device == device) && (element->index == index) && (id < MAX_ID) ) { element->state[id] = value; return; } } element = (InputListElement*) mylist_add_element(input_state_list); element->port = port; element->device = device; element->index = index; if (id < MAX_ID) element->state[id] = value; }
static void input_state_set_last(unsigned port, unsigned device, unsigned index, unsigned id, int16_t value) { unsigned i; InputListElement *element = NULL; if (id >= 65536) return; /*arbitrary limit of up to 65536 elements in state array*/ if (!input_state_list) mylist_create(&input_state_list, 16, InputListElementConstructor, InputListElementDestructor); /* find list item */ for (i = 0; i < (unsigned)input_state_list->size; i++) { element = (InputListElement*)input_state_list->data[i]; if ( (element->port == port) && (element->device == device) && (element->index == index) ) { if (id >= element->state_size) InputListElementExpand(element, id); element->state[id] = value; return; } } element = (InputListElement*) mylist_add_element(input_state_list); element->port = port; element->device = device; element->index = index; if (id >= element->state_size) { InputListElementExpand(element, id); } element->state[id] = value; }