fixed various bugs

xkbcommon
Alessandro Mauri 5 years ago
parent e0a64d75c7
commit 678fef9358
  1. 18
      macrod.c

@ -15,6 +15,8 @@
/* Signaling */ /* Signaling */
#include <signal.h> #include <signal.h>
#define test_bit(yalv, abs_b) ((((char *)abs_b)[yalv/8] & (1<<yalv%8)) > 0)
/* Determine dependencies based on platform */ /* Determine dependencies based on platform */
#ifdef __linux__ #ifdef __linux__
#define OS linux #define OS linux
@ -57,7 +59,8 @@ int main (void)
/* Open the event directory */ /* Open the event directory */
DIR *ev_dir = opendir(ev_root); DIR *ev_dir = opendir(ev_root);
if (!ev_dir) die(); if (!ev_dir)
die();
int fd_num = 0; int fd_num = 0;
struct pollfd *fds = NULL; struct pollfd *fds = NULL;
@ -67,7 +70,7 @@ int main (void)
char ev_path[sizeof(ev_root) + NAME_MAX + 1]; char ev_path[sizeof(ev_root) + NAME_MAX + 1];
void *tmp_p; void *tmp_p;
int tmp_fd; int tmp_fd;
unsigned char evtype_b[EV_MAX/8 + 1]; unsigned char evtype_b[EV_MAX];
if ((file_ent = readdir(ev_dir)) == NULL) if ((file_ent = readdir(ev_dir)) == NULL)
break; break;
@ -86,6 +89,7 @@ int main (void)
continue; continue;
} }
memset(evtype_b, 0, sizeof(evtype_b));
if (ioctl(tmp_fd, EVIOCGBIT(0, EV_MAX), evtype_b) < 0) { if (ioctl(tmp_fd, EVIOCGBIT(0, EV_MAX), evtype_b) < 0) {
fprintf(stderr, "Could not read capabilities of device %s\n", fprintf(stderr, "Could not read capabilities of device %s\n",
ev_path); ev_path);
@ -93,7 +97,7 @@ int main (void)
continue; continue;
} }
if (!(*evtype_b & EV_KEY)) { if (!test_bit(EV_KEY, evtype_b)) {
fprintf(stderr, "Ignoring device %s\n", ev_path); fprintf(stderr, "Ignoring device %s\n", ev_path);
close(tmp_fd); close(tmp_fd);
continue; continue;
@ -154,7 +158,7 @@ int main (void)
#endif #endif
static int i; static int i;
static int prev_size; static unsigned int prev_size;
prev_size = pb.size; prev_size = pb.size;
for (i = 0; i < fd_num; i++) { for (i = 0; i < fd_num; i++) {
@ -192,7 +196,7 @@ int main (void)
if (pb.size != prev_size) { if (pb.size != prev_size) {
printf("Pressed keys: "); printf("Pressed keys: ");
for (int i = 0; i < pb.size; i++) for (unsigned int i = 0; i < pb.size; i++)
printf("%d ", pb.buf[i]); printf("%d ", pb.buf[i]);
putchar('\n'); putchar('\n');
if (pb.size == 2) if (pb.size == 2)
@ -222,7 +226,7 @@ int pressBufferAdd (struct pressed_buffer *pb, unsigned short key)
if (!pb) return 1; if (!pb) return 1;
if (pb->buf != NULL) { if (pb->buf != NULL) {
/* Linear search if the key is already buffered */ /* Linear search if the key is already buffered */
for (int i = 0; i < pb->size; i++) for (unsigned int i = 0; i < pb->size; i++)
if (key == pb->buf[i]) return 1; if (key == pb->buf[i]) return 1;
} }
@ -244,7 +248,7 @@ int pressBufferRemove (struct pressed_buffer *pb, unsigned short key)
* non zero in case of failure (key not present or buffer empty). */ * non zero in case of failure (key not present or buffer empty). */
if (!pb) return 1; if (!pb) return 1;
for (int i = 0; i < pb->size; i++) { for (unsigned int i = 0; i < pb->size; i++) {
if (pb->buf[i] == key) { if (pb->buf[i] == key) {
pb->size--; pb->size--;
pb->buf[i] = pb->buf[pb->size]; pb->buf[i] = pb->buf[pb->size];

Loading…
Cancel
Save