Пример #1
0
int
main(int argc, char **argv)
{
        char *correct, *guess, *file, guess_char, true_char;
        int known_incorrect = 0, i;
        FILE *f;

        if (argc != 3) {
                fprintf(stderr, "Usage: %s file guess\n\nCompares the contents of a file with a guess, and\nmakes fun of you if you didn't get it right.\n", argv[0]);
                exit(1);
        }

        file = argv[1];
        guess = argv[2];

        if (!(correct = malloc(1024))) {
                fprintf(stderr, "Error allocating buffer\n");
                exit(1);
        }

        if (!(f = fopen(file, "r"))) {
                fprintf(stderr, "Error opening file: %s\n", file);
                exit(1);
        }

        if (!fgets(correct, 1024, f)) {
                fprintf(stderr, "Error reading file: %s\n", file);
                exit(1);
        }

        if (correct[strlen(correct)-1] == '\n')
                correct[strlen(correct)-1] = '\0';

        fprintf(stderr, "Welcome to the password checker!\n");

        for (i = 0; i < strlen(guess); i++) {
                guess_char = char_at(guess, i);
                true_char = char_at(correct, i);
                fprintf(stderr, ".");
                if (!known_incorrect && (guess_char != true_char)) {
                        known_incorrect = 1;
                        taunt();
                }
        }

        if (!known_incorrect && strlen(guess) != strlen(correct)) {
                known_incorrect = 1;
                taunt();
        }

        fprintf(stderr, "\n");

        if (!known_incorrect) {
                fprintf(stderr, "Wait, how did you know that the password was %s?\n", correct);
        }

        return 0;
}
Пример #2
0
void fs_emu_handle_libfsemu_action(int action, int state)
{
    if (g_fs_log_input)
        fs_log("fs_emu_handle_libfsemu_action %d %d\n", action, state);

    switch (action) {
    case FS_EMU_ACTION_FULL_KEYBOARD:
        if (state) {
            fs_emu_set_full_keyboard_emulation(
                !fs_emu_full_keyboard_emulation(), true);
        }
        break;
    case FS_EMU_ACTION_FULLSCREEN:
        if (state)
            fs_emu_toggle_fullscreen();
        break;
    case FS_EMU_ACTION_GRAB_INPUT:
        if (state) {
            if (g_fs_emu_grab_input_on_mod_release) {
                /* We had grapped the input, but is holding the modifier
                 * key. So we just don't ungrab on release. */
                g_fs_emu_grab_input_on_mod_release = false;
                fs_emu_show_cursor_msec(FS_EMU_MOUSE_DEFAULT_DURATION);
            } else {
                fs_emu_set_input_grab(!fs_emu_input_grab());
            }
        }
        break;
    case FS_EMU_ACTION_MENU_ALT:
        if (state)
            fs_emu_menu_toggle();
        break;
    case FS_EMU_ACTION_PAUSE:
        if (state)
            fs_emu_pause(!fs_emu_is_paused());
        break;
    case FS_EMU_ACTION_QUIT:
        if (state)
            fs_emu_quit();
        break;
    case FS_EMU_ACTION_SCREENSHOT:
        if (state)
            g_fs_emu_screenshot = 1;
        break;
    case FS_EMU_ACTION_SPECIAL:
        if (state)
            special_function();
        break;
    case FS_EMU_ACTION_SWITCH_WINDOW:
        if (state)
            switch_window();
        break;
    case FS_EMU_ACTION_TAUNT:
        if (state)
            taunt();
        break;
    case FS_EMU_ACTION_VOLUME_DOWN:
        if (state)
            fs_emu_volume_control(-2);
        break;
    case FS_EMU_ACTION_VOLUME_MUTE:
        if (state)
            fs_emu_volume_control(-1);
        break;
    case FS_EMU_ACTION_VOLUME_UP:
        if (state)
            fs_emu_volume_control(-3);
        break;
    case FS_EMU_ACTION_WARP:
        if (state) {
            /* FIXME: UAE-specific hot key hack for warp function,
             * should be moved out of libfsemu. */
            fs_emu_queue_input_event(0x00010000 | 275);
        }
        break;
    case FS_EMU_ACTION_ZOOM:
        if (state) {
            fs_emu_toggle_zoom(0);
        }
        break;
    case FS_EMU_ACTION_ZOOM_BORDER:
        if (state) {
            fs_emu_toggle_zoom(1);
        }
        break;
    case FSE_ACTION_CYCLE_STRETCH_MODE:
        if (state) {
            fse_cycle_stretch_mode();
        }
        break;
    }
}