////////////////////////////////////////////////////////////////////// // Add an item to the end of its "priority group" // The list is assumed to be sorted already... int LL_PriorityEnqueue (LinkedList * list, void *add, int compare (void *, void *)) { void *data; int i; if (!list) return -1; if (!add) return -1; if (!compare) return -1; // From the end of the list, keep searching while we're "less than" // the given nodes... LL_End (list); do { data = LL_Get (list); if (data) { i = compare (add, data); if (i >= 0) // If we're in the right place, add it and exit { LL_AddNode (list, add); return 0; } } } while (LL_Prev (list) == 0); // If we're less than *everything*, put it at the beginning LL_Unshift (list, add); return 0; }
////////////////////////////////////////////////////////////////////// // Stack operations int LL_Push (LinkedList * list, void *add) // Add node to end of list { if (!list) return -1; if (!add) return -1; // printf("Going to end of list...\n"); LL_End (list); // printf("Adding node...\n"); return LL_AddNode (list, add); }
/** * Initialize the driver. * \param drvthis Pointer to driver structure. * \retval 0 Success. * \retval <0 Error. */ MODULE_EXPORT int linuxInput_init (Driver *drvthis) { PrivateData *p; const char *s; struct keycode *key; int i; /* Allocate and store private data */ p = (PrivateData *) calloc(1, sizeof(PrivateData)); if (p == NULL) return -1; if (drvthis->store_private_ptr(drvthis, p)) return -1; /* initialize private data */ p->fd = -1; if ((p->buttonmap = LL_new()) == NULL) { report(RPT_ERR, "%s: cannot allocate memory for buttons", drvthis->name); return -1; } /* Read config file */ /* What device should be used */ s = drvthis->config_get_string(drvthis->name, "Device", 0, LINUXINPUT_DEFAULT_DEVICE); report(RPT_INFO, "%s: using Device %s", drvthis->name, s); if ((p->fd = open(s, O_RDONLY | O_NONBLOCK)) < 0) { report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, s, strerror(errno)); return -1; } for (i = 0; (s = drvthis->config_get_string(drvthis->name, "key", i, NULL)) != NULL; i++) { if ((key = keycode_create(s)) == NULL) { report(RPT_ERR, "%s: parsing configvalue '%s' failed", drvthis->name, s); continue; } LL_AddNode(p->buttonmap, key); } report(RPT_DEBUG, "%s: init() done", drvthis->name); return 0; }