void printFreq(WorkerThread* threads, int cpus, float totalCount) { HashTable<KEY_SIZE> sum; for (int i=0; i<cpus; i++) { merge_table(sum, *((HashTable<KEY_SIZE>*)threads[i].hashByLength(KEY_SIZE))); } typedef std::pair< Key<KEY_SIZE>, uint32_t > hash_pair_t; std::vector<hash_pair_t> list(sum.begin(), sum.end()); std::sort(list.begin(), list.end(), greater_second<hash_pair_t>()); for (typename std::vector<hash_pair_t>::iterator it = list.begin(); it < list.end(); ++it) { char key[KEY_SIZE+1]; for (int i=0; i<KEY_SIZE; i++) key[i] = toupper((*it).first.key[i]); key[KEY_SIZE] = 0; printf("%s %.3f\n", key, (float)((*it).second) * 100.0f / totalCount); } printf("\n"); }
int main(int argc, char **argv) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "interactive", no_argument, NULL, 'i' }, {} }; int fd = -1; int opt_interactive = 0; int i; while (1) { int option; option = getopt_long(argc, argv, "hi", options, NULL); if (option == -1) break; switch (option) { case 'h': help(0); case 'i': opt_interactive = 1; break; default: return 1; } } if (argc < optind+1) help (1); if ((fd = evdev_open(argv[optind])) < 0) return 3; /* one argument (device): dump or interactive */ if (argc == optind+1) { if (opt_interactive) interactive(fd); else dump_table(fd); return 0; } /* two arguments (device, mapfile): set map file */ if (argc == optind+2) { merge_table(fd, default_keymap_path(argv[optind+1])); return 0; } /* more arguments (device, scancode/keyname pairs): set keys directly */ if ((argc - optind - 1) % 2 == 0) { for (i = optind+1; i < argc; i += 2) set_key(fd, argv[i], argv[i+1]); return 0; } /* invalid number of arguments */ help(1); return 1; /* not reached */ }
int main(int argc, char **argv) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "interactive", no_argument, NULL, 'i' }, {} }; int fd = -1; int opt_interactive = 0; int i; while (1) { int option; option = getopt_long(argc, argv, "hi", options, NULL); if (option == -1) break; switch (option) { case 'h': help(0); case 'i': opt_interactive = 1; break; default: return 1; } } if (argc < optind+1) help (1); if ((fd = evdev_open(argv[optind])) < 0) return 3; /* one argument (device): dump or interactive */ if (argc == optind+1) { if (opt_interactive) interactive(fd); else dump_table(fd); return 0; } /* two arguments (device, mapfile): set map file */ if (argc == optind+2) { const char *filearg = argv[optind+1]; if (strchr(filearg, '/')) { /* Keymap file argument is a path */ FILE *f = fopen(filearg, "re"); if (f) merge_table(fd, f); else perror(filearg); } else { /* Keymap file argument is a filename */ /* Open override file if present, otherwise default file */ char keymap_path[PATH_MAX]; FILE *f; snprintf(keymap_path, sizeof(keymap_path), "/etc/udev/keymaps/%s", filearg); f = fopen(keymap_path, "re"); if (f) { merge_table(fd, f); } else { snprintf(keymap_path, sizeof(keymap_path), UDEVLIBEXECDIR "/keymaps/%s", filearg); f = fopen(keymap_path, "re"); if (f) merge_table(fd, f); else perror(keymap_path); } } return 0; } /* more arguments (device, scancode/keyname pairs): set keys directly */ if ((argc - optind - 1) % 2 == 0) { for (i = optind+1; i < argc; i += 2) set_key(fd, argv[i], argv[i+1]); return 0; } /* invalid number of arguments */ help(1); return 1; /* not reached */ }