void PredicateChecker::push_path(const std::string &path) { if(path.empty()) { return; } size_t pos = 0; size_t last_pos = 0; size_t count = 1; // Split up condensed paths... while((pos = path.find_first_of('.', last_pos)) != std::string::npos) { const std::string key = path.substr(last_pos, pos-last_pos); last_pos = pos+1; push_key(key); count++; } const std::string last_key = path.substr(last_pos, std::string::npos); push_key(last_key); m_path_sizes.push(count); }
void releasebutton(short code) { int kbcode = AKEY_NONE, temp_ui = -1; if(ui_is_active) release_key(kbcode); else { if(code == joykey_map[get_screen_mode()][0]) stick0 |= 1; else if(code == joykey_map[get_screen_mode()][1]) stick0 |= 2; else if(code == joykey_map[get_screen_mode()][2]) stick0 |= 4; else if(code == joykey_map[get_screen_mode()][3]) stick0 |= 8; else if(code == klist.vkA || code == klist.vkB || ((code == '4' || code == '6') && issmartphone)) trig0 = 1; else if(code == klist.vkC) if (kbui_timerset) { KillTimer(hWndMain, 1); kbui_timerset = FALSE; set_screen_mode(0); kbcode = AKEY_UI; push_key(kbcode); ui_clearkey = TRUE; return; } } release_key(kbcode); // always release or the ui gets stuck }
int main(int argc, char **argv){ to_visit = create_stack(); visited = create_empty_list(); char *path = NULL; if(argc > 2){ usage(); exit(-1); } //start search at specified directory if(argc == 2){ path = *(argv+1); } //start search at current working directory (default behavior) else{ path = "."; } push_key(to_visit, path); char *cur; while(!is_stack_empty(to_visit)){ cur = (char *)(pop(to_visit)->data); if(process(cur) == -1){ break; } } print_results(); return 0; }
test_case mixed_workload( int initial_insertions, int total_insertions, int removals, int search_successes, int search_failures, unsigned int seed ) { std::mt19937 rng(seed); test_case ret( total_insertions + removals + search_successes + search_failures ); auto rem = efficiently_choose_target_to_remove{ std::vector<std::pair<int,bool>>(initial_insertions), initial_insertions }; for( int i = 0; i < total_insertions; i++ ) ret[i] = operation{ operation_type::insert, 2 * i + 2 }; std::shuffle( ret.begin(), ret.begin() + total_insertions, rng ); /* The first initial_insertions values will not be changed anymore. * The other values will be shuffled together with the other values. */ for( int i = 0; i < initial_insertions; i++ ) rem.keys[i] = std::make_pair( ret[i].key, true ); // rem is usable. for( int i = 0; i < removals; i++ ) ret[i+total_insertions].type = operation_type::erase; for( int i = 0; i < search_successes + search_failures; i++ ) ret[i+total_insertions+removals].type = operation_type::count; std::shuffle( ret.begin()+initial_insertions, ret.end(), rng ); /* All the operation types are correctly set, * and every insert operation has the correct key set. * Now, we will set the keys of the removals and the searches. */ auto bits = random_bits(search_failures, search_successes, rng); int decision = 0; std::uniform_int_distribution<> failure(0, total_insertions); for( int i = initial_insertions; i < ret.size(); i++ ) { switch( ret[i].type ) { case operation_type::insert: rem.push_key( ret[i].key ); break; case operation_type::erase: ret[i].key = rem.get_key(rng); break; case operation_type::count: if( bits[decision++] ) ret[i].key = rem.peek_key(rng); else ret[i].key = 2*failure(rng) + 1; break; } } return ret; }
//-1 is an error, 0 is success int walk_dir(char *path){ DIR *cd; struct dirent *dirp; if(!(cd = opendir(path))){ printf("Error opening %s\n", path); return -1; } while((dirp = readdir(cd))){ //skip '.' if(!strcmp(dirp->d_name, ".")){ continue; } //skip '..' if(!strcmp(dirp->d_name, "..")){ continue; } if(!strcmp(path, "/")){ int p_len = strlen(dirp->d_name) + 2; char *new_path = calloc(p_len, sizeof(char)); strcpy(new_path, path); strcat(new_path, dirp->d_name); push_key(to_visit, new_path); } else if(strcmp(path, ".") || strcmp(path, "..")){ int p_len = strlen(path) + strlen(dirp->d_name)+2; char *new_path = calloc(p_len, sizeof(char)); strcpy(new_path, path); strcat(new_path, "/"); strcat(new_path, dirp->d_name); push_key(to_visit, new_path); } else{ push_key(to_visit, dirp->d_name); } } closedir(cd); return 0; }
// helps us be lazy by pretending joysticks are a keyboard (useful for menus) void push_joysticks_as_keyboard( void ) { const SDLKey confirm = SDLK_RETURN, cancel = SDLK_ESCAPE; const SDLKey direction[4] = { SDLK_UP, SDLK_RIGHT, SDLK_DOWN, SDLK_LEFT }; poll_joysticks(); for (int j = 0; j < joysticks; j++) { if (!joystick[j].input_pressed) continue; if (joystick[j].confirm) push_key(confirm); if (joystick[j].cancel) push_key(cancel); for (uint d = 0; d < COUNTOF(joystick[j].direction_pressed); d++) { if (joystick[j].direction_pressed[d]) push_key(direction[d]); } } }
void Start_KBUI(void) { int kbcode, temp_ui; KillTimer(hWndMain, 1); kbui_timerset = FALSE; temp_ui = ui_is_active; ui_is_active = TRUE; kbcode = kb_ui("Select Atari key to inject once", machine_type); if (kbcode != AKEY_NONE) push_key(kbcode); else release_key(AKEY_NONE); ui_is_active = temp_ui; return; }
void process_key(int id, int st) { switch(mode[active_layer*4*12+id]) { case MODE_K: if(st && state[id]) push_key(matrix[active_layer*4*12+id]); break; case MODE_M: if(st && state[id]) push_modifier(matrix[active_layer*4*12+id]); break; case MODE_L: if( (st && state[id]) || ( (!st) && (!state[id]) ) ) special(matrix[active_layer*4*12+id],st); break; default: break; } state[id] = st; }
uni_t dpy_getchar(int timeout) { while (numqueued == 0) { /* If a timeout was asked for, wait that long for an event. */ if ((timeout != -1) && !XPending(display)) { struct pollfd pfd = { .fd = ConnectionNumber(display), .events = POLLIN, .revents = 0 }; poll(&pfd, 1, timeout*1000); if (!pfd.revents) return -VK_TIMEOUT; } XEvent e; XNextEvent(display, &e); if (XFilterEvent(&e, window)) continue; switch (e.type) { case MapNotify: break; case Expose: { /* Mark some of the screen as needing redrawing. */ if (frontbuffer) { for (int y=0; y<screenheight; y++) { unsigned int* p = &frontbuffer[y * screenwidth]; for (int x=0; x<screenwidth; x++) p[x] = 0; } } redraw(); break; } case ConfigureNotify: { XConfigureEvent* xce = &e.xconfigure; int w = xce->width / fontwidth; int h = xce->height / fontheight; if ((w != screenwidth) || (h != screenheight)) { screenwidth = w; screenheight = h; if (frontbuffer) free(frontbuffer); frontbuffer = NULL; if (backbuffer) free(backbuffer); backbuffer = calloc(screenwidth * screenheight, sizeof(unsigned int)); push_key(-VK_RESIZE); } break; } case MappingNotify: case KeymapNotify: XRefreshKeyboardMapping(&e.xmapping); break; case KeyPress: { XKeyPressedEvent* xke = &e.xkey; KeySym keysym; char buffer[32]; Status status = 0; int charcount = Xutf8LookupString(xic, xke, buffer, sizeof(buffer)-1, &keysym, &status); int mods = 0; if (xke->state & ShiftMask) mods |= VKM_SHIFT; if (xke->state & ControlMask) mods |= VKM_CTRL; if ((keysym & 0xffffff00) == 0xff00) { /* Special function key. */ if (!IsModifierKey(keysym)) push_key(-(keysym | mods)); } else { const char* p = buffer; while ((p-buffer) < charcount) { uni_t c = readu8(&p); if (c < 32) { /* Ctrl + letter key */ push_key(-(VKM_CTRLASCII | c | mods)); } else { if (xke->state & Mod1Mask) push_key(-XK_Escape); push_key(c); } } } break; } } } return dequeue(); } const char* dpy_getkeyname(uni_t k) { static char buffer[32]; switch (-k) { case VK_RESIZE: return "KEY_RESIZE"; case VK_TIMEOUT: return "KEY_TIMEOUT"; case VK_REDRAW: return "KEY_REDRAW"; } int key = -k & ~VKM__MASK; int mods = -k & VKM__MASK; if (mods & VKM_CTRLASCII) { sprintf(buffer, "KEY_%s^%c", (mods & VKM_SHIFT) ? "S" : "", key + 64); return buffer; } const char* template = NULL;
void tapscreen(short x, short y) { short kbcode; stylus_down = 1; /* On-screen joystick */ if(virtual_joystick && !ui_is_active && currentKeyboardMode == 4 && y < 240) { stick0 = 0xff; trig0 = 1; if(y < 90) /* up */ stick0 &= ~1; if(y >= 150) /* down */ stick0 &= ~2; if(x < 120) /* left */ stick0 &= ~4; if(x >= 200) /* right */ stick0 &= ~8; if(x >= 60 && x < 260 && y >= 45 && y < 195) trig0 = 0; return; } translate_kbd(&x, &y); /* In landscape - show keyboard if clicked bottom right corner */ if(get_screen_mode() && currentKeyboardMode == 4 && x > 300 && y > 220) return; kbcode = get_keypress(x, y); /* Special keys */ switch(kbcode) { case KBD_ROTATE: case KBD_NEGATE: case KBD_HIDE: return; } /* The way current UI works, it is not compatible with keyboard implementation in landscape mode */ if(kbcode == AKEY_UI) set_screen_mode(0); /* Special translation to make on-screen UI easier to use */ if(ui_is_active) { if(machine_type == MACHINE_5200) { switch(kbcode) { case 0x3d: /* 2 */ kbcode = AKEY_UP; break; case 0x2d: /* 8 */ kbcode = AKEY_DOWN; break; case 0x37: /* 4 */ kbcode = AKEY_LEFT; break; case 0x33: /* 6 */ kbcode = AKEY_RIGHT; break; case 0x39: /* Start */ kbcode = AKEY_RETURN; break; case 0x27: /* * */ kbcode = AKEY_ESCAPE; break; case 0x31: /* Pause */ kbcode = AKEY_TAB; break; case 0x23: /* # */ kbcode = AKEY_SPACE; break; } } else { switch(kbcode) { case AKEY_MINUS: kbcode = AKEY_UP; break; case AKEY_EQUAL: kbcode = AKEY_DOWN; break; case AKEY_PLUS: kbcode = AKEY_LEFT; break; case AKEY_ASTERISK: kbcode = AKEY_RIGHT; break; } } } push_key(kbcode); }
void hitbutton(short code) { int kbcode = AKEY_NONE; if(ui_is_active) { trig0 = 1; stick0 = 0xff; if(code == joykey_map[get_screen_mode()][0]) kbcode = AKEY_UP; else if(code == joykey_map[get_screen_mode()][1]) kbcode = AKEY_DOWN; else if(code == joykey_map[get_screen_mode()][2]) kbcode = AKEY_LEFT; else if(code == joykey_map[get_screen_mode()][3]) kbcode = AKEY_RIGHT; else if(code == klist.vkStart && !issmartphone) kbcode = AKEY_BACKSPACE; else if(code == klist.vkA) kbcode = AKEY_SPACE; else if(code == klist.vkB) kbcode = AKEY_RETURN; else if(code == klist.vkC) kbcode = AKEY_ESCAPE; else for(int i=0; i<sizeof(kbd_translation)/sizeof(kbd_translation[0]); i++) if(code == kbd_translation[i].winKey) { kbcode = kbd_translation[i].aKey; break; } } else { if(code == joykey_map[get_screen_mode()][0]) stick0 &= ~1; else if(code == joykey_map[get_screen_mode()][1]) stick0 &= ~2; else if(code == joykey_map[get_screen_mode()][2]) stick0 &= ~4; else if(code == joykey_map[get_screen_mode()][3]) stick0 &= ~8; else if(code == klist.vkA || code == klist.vkB || ((code == '4' || code == '6') && issmartphone)) trig0 = 0; else if(code == klist.vkC) { if (!kbui_timerset) { SetTimer(hWndMain, 1, 1000, NULL); kbui_timerset = TRUE; } } else if ((code == VK_F3) && (issmartphone)) set_screen_mode(get_screen_mode()+1); else for(int i=0; i<sizeof(kbd_translation)/sizeof(kbd_translation[0]); i++) if(code == kbd_translation[i].winKey) { kbcode = kbd_translation[i].aKey; break; } } if(kbcode != AKEY_NONE) push_key(kbcode); }
void hitbutton(short code) { int kbcode; if(ui_is_active) { trig0 = 1; stick0 = 0xff; kbcode = AKEY_NONE; if(code == joykey_map[get_screen_mode()][0]) kbcode = AKEY_UP; else if(code == joykey_map[get_screen_mode()][1]) kbcode = AKEY_DOWN; else if(code == joykey_map[get_screen_mode()][2]) kbcode = AKEY_LEFT; else if(code == joykey_map[get_screen_mode()][3]) kbcode = AKEY_RIGHT; else if(code == klist.vkStart) kbcode = AKEY_TAB; else if(code == klist.vkA) kbcode = AKEY_SPACE; else if(code == klist.vkB) kbcode = AKEY_RETURN; else if(code == klist.vkC) kbcode = AKEY_ESCAPE; push_key(kbcode); } else { kbcode = AKEY_NONE; if(code == joykey_map[get_screen_mode()][0]) stick0 &= ~1; else if(code == joykey_map[get_screen_mode()][1]) stick0 &= ~2; else if(code == joykey_map[get_screen_mode()][2]) stick0 &= ~4; else if(code == joykey_map[get_screen_mode()][3]) stick0 &= ~8; else if(code == klist.vkA || code == klist.vkB) trig0 = 0; else if(code == klist.vkC) kbcode = AKEY_UI; else for(int i=0; i<sizeof(kbd_translation)/sizeof(kbd_translation[0]); i++) if(code == kbd_translation[i].winKey) { kbcode = kbd_translation[i].aKey; break; } if(kbcode != AKEY_NONE) push_key(kbcode); } /* The way current UI works, it is not compatible with keyboard implementation in landscape mode */ if(kbcode == AKEY_UI) set_screen_mode(0); }