#include #include #include #include #include #include #include #include int main (int argc, char **argv) { int fd; FILE *fp = NULL; ENTRY e; char str[1024] = {0}, *p; struct input_event ie; struct tm *tm; hcreate(255); if (argc!=2) { fprintf(stderr, "usage: %s /dev/input/eventX\n",argv[0]); exit(errno); } if ((fd=open(argv[1], O_RDONLY))<0) { fprintf(stderr, "%s: can't open device %s\n",argv[0],argv[1]); exit(errno); } if (p = getenv("HOME")) { sprintf(str,"%s/.eventdrc",p); fp = fopen(str, "r"); } if (!fp && (fp=fopen(EVCONF, "r"))==NULL) { fprintf(stderr, "%s: can't open conf file "EVCONF"\n",argv[0]); exit(errno); } /* parse the conf file */ while(!feof(fp)) { fgets(str, 1023, fp); if (*str == '#' || *str == '\n' || *str == ' ') continue; if ((p = strchr(str, ':'))==NULL) continue; e.key = strdup(str); p = strchr(e.key, ':'); for (*p++='\0'; isspace(*p); ++p); e.data=p; hsearch(e, ENTER); } fclose(fp); /* start reading the /dev/input/eventX device */ for (;;) { ENTRY *ef; read(fd, &ie, sizeof(ie)); /* only do key down events */ if (!ie.value) continue; sprintf(str,"%d",ie.code); e.key=str; if ((ef=hsearch(e,FIND))==NULL) continue; system(ef->data); } /* we actually never reach here, need to put this in a signal handler */ hdestroy(); exit (0); }