예제 #1
0
/**
 * Capture a regular expression from the user, one key at a time.
 * This modifies the global variables regex_cur and regex_last.
 *
 * \param sview
 * The source viewer.
 *
 * \return
 * 0 if user gave a regex, otherwise 1.
 */
static int status_bar_regex_input(struct sviewer *sview, int key)
{
    int regex_icase = cgdbrc_get(CGDBRC_IGNORECASE)->variant.int_val;

    /* Flag to indicate we're done with regex mode, need to switch back */
    int done = 0;

    /* Recieve a regex from the user. */
    switch (key) {
        case '\r':
        case '\n':
        case CGDB_KEY_CTRL_M:
            /* Save for future searches via 'n' or 'N' */
            if (regex_last != NULL) {
                ibuf_free(regex_last);
            }
            regex_last = ibuf_dup(regex_cur);
            regex_direction_last = regex_direction_cur;
            source_search_regex(sview, ibuf_get(regex_last), 2,
                    regex_direction_last, regex_icase);
            if_draw();
            done = 1;
            break;
        case 8:
        case 127:
            /* Backspace or DEL key */
            if (ibuf_length(regex_cur) == 0) {
                done = 1;
            } else {
                ibuf_delchar(regex_cur);
                source_search_regex(sview, ibuf_get(regex_cur), 1,
                        regex_direction_cur, regex_icase);
                if_draw();
                update_status_win();
            }
            break;
        default:
            if (kui_term_is_cgdb_key(key)) {
                const char *keycode = kui_term_get_keycode_from_cgdb_key(key);
                int length = strlen(keycode), i;

                for (i = 0; i < length; i++)
                    ibuf_addchar(regex_cur, keycode[i]);
            } else {
                ibuf_addchar(regex_cur, key);
            }
            source_search_regex(sview, ibuf_get(regex_cur), 1,
                    regex_direction_cur, regex_icase);
            if_draw();
            update_status_win();
    };

    if (done) {
        ibuf_free(regex_cur);
        regex_cur = NULL;
        if_set_focus(CGDB);
    }

    return 0;
}
예제 #2
0
파일: kui_term.c 프로젝트: rsenn/cgdb
int 
kui_term_print_key_array (int *cgdb_key_array)
{
	int i;

	if ( !cgdb_key_array )
		return -1;

	/* Display output buffer */
	fprintf ( stderr, "CGDB_KEY_ARRAY(");

	for ( i = 0; cgdb_key_array[i] != 0; i++ ) {
		int is_ckey;

		is_ckey = kui_term_is_cgdb_key ( cgdb_key_array[i] );

		if ( is_ckey ) {
			fprintf ( stderr, "%s", kui_term_get_string_from_key (cgdb_key_array[i]));	
		} else {
			fprintf ( stderr, "%c", cgdb_key_array[i] );
		}
	}

	fprintf ( stderr, ")\r\n" );

	return 0;
}
예제 #3
0
파일: cgdb.c 프로젝트: i4fumi/cgdb
/* user_input: This function will get a key from the user and process it.
 *
 *  Returns:  -1 on error, 0 on success
 */
static int user_input(void)
{
    static int key, val;

    /* Clear the current map sets. Give the KUI the map sets 
     * that should be used with the current focus.
     */
    val = kui_manager_clear_map_sets(kui_ctx);
    if (val == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "user_input error");
        return -1;
    }

    if (if_get_focus() == CGDB)
        val = kui_manager_add_map_set(kui_ctx, kui_map);
    else if (if_get_focus() == GDB)
        val = kui_manager_add_map_set(kui_ctx, kui_imap);

    key = kui_manager_getkey(kui_ctx);
    if (key == -1) {
        logger_write_pos(logger, __FILE__, __LINE__,
                "kui_manager_getkey error");
        return -1;
    }

    val = if_input(key);

    if (val == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "if_input error");
        return -1;
    } else if (val != 1 && val != 2)
        return 0;

    if (val == 1 && completion_ptr)
        return handle_tab_completion_request(completion_ptr, key);

    /* Process the key */
    if (kui_term_is_cgdb_key(key)) {
        char *seqbuf = kui_term_get_ascii_char_sequence_from_key(key);

        if (seqbuf == NULL) {
            logger_write_pos(logger, __FILE__, __LINE__,
                    "kui_term_get_ascii_char_sequence_from_key error %d", key);
            return -1;
        } else {
            int length = strlen(seqbuf), i;

            for (i = 0; i < length; i++)
                send_key(val, seqbuf[i]);
        }
    } else
        send_key(val, key);

    return 0;
}
예제 #4
0
static int status_bar_normal_input(int key)
{
    /* Flag to indicate we're done with status mode, need to switch back */
    int done = 0;

    /* The goal of this state is to recieve a command from the user. */
    switch (key) {
        case '\r':
        case '\n':
        case CGDB_KEY_CTRL_M:
            /* Found a command */
            if_run_command(src_win, cur_sbc);
            done = 1;
            break;
        case 8:
        case 127:
            /* Backspace or DEL key */
            if (ibuf_length(cur_sbc) == 0) {
                done = 1;
            } else {
                ibuf_delchar(cur_sbc);
                update_status_win();
            }
            break;
        default:
            if (kui_term_is_cgdb_key(key)) {
                const char *keycode = kui_term_get_keycode_from_cgdb_key(key);
                int length = strlen(keycode), i;

                for (i = 0; i < length; i++)
                    ibuf_addchar(cur_sbc, keycode[i]);
            } else {
                ibuf_addchar(cur_sbc, key);
            }
            update_status_win();
            break;
    };

    if (done) {
        ibuf_free(cur_sbc);
        cur_sbc = NULL;
        if_set_focus(CGDB);
    }

    return 0;
}
예제 #5
0
파일: interface.cpp 프로젝트: ibuclaw/cgdb
/**
 * Capture a regular expression from the user, one key at a time.
 * This modifies the global variables regex_cur and regex_last.
 *
 * \param sview
 * The source viewer.
 *
 * \return
 * 0 if user gave a regex, otherwise 1.
 */
static int gdb_input_regex_input(struct scroller *scr, int key)
{
    int regex_icase = cgdbrc_get_int(CGDBRC_IGNORECASE);

    /* Flag to indicate we're done with regex mode, need to switch back */
    int done = 0;

    /* Receive a regex from the user. */
    switch (key)
    {
    case '\r':
    case '\n':
    case CGDB_KEY_CTRL_M:
        /* Save for future searches via 'n' or 'N' */
        ibuf_free(regex_last);
        regex_last = ibuf_dup(regex_cur);

        regex_direction_last = regex_direction_cur;
        scr_search_regex(scr, ibuf_get(regex_last), 2,
            regex_direction_last, regex_icase);
        if_draw();
        done = 1;
        break;
    case 8:
    case 127:
        /* Backspace or DEL key */
        if (ibuf_length(regex_cur) == 0)
        {
            done = 1;
            scr_search_regex(scr, "", 2,
                regex_direction_cur, regex_icase);
        }
        else
        {
            ibuf_delchar(regex_cur);
            scr_search_regex(scr, ibuf_get(regex_cur), 1,
                regex_direction_cur, regex_icase);
            if_draw();
            update_status_win(WIN_REFRESH);
        }
        break;
    default:
        if (kui_term_is_cgdb_key(key))
        {
            const char *keycode = kui_term_get_keycode_from_cgdb_key(key);
            int length = strlen(keycode), i;

            for (i = 0; i < length; i++)
                ibuf_addchar(regex_cur, keycode[i]);
        }
        else
        {
            ibuf_addchar(regex_cur, key);
        }
        scr_search_regex(scr, ibuf_get(regex_cur), 1,
            regex_direction_cur, regex_icase);
        if_draw();
        update_status_win(WIN_REFRESH);
    };

    if (done)
    {
        gdb_scroller->in_search_mode = 0;

        ibuf_free(regex_cur);
        regex_cur = NULL;

        sbc_kind = SBC_NORMAL;
        if_set_focus(GDB);
    }

    return 0;
}