Exemplo n.º 1
0
static int test_delchar(ibuf s)
{

    /* Delete the last '!' from the string. */
    ibuf_delchar(s);

    /* Make sure it was deleted correctly. */
    if (strcmp(ibuf_get(s), "hello world") != 0) {
        debug("test_delchar: Mismatch, expected \"hello world\", got: %s\n",
                ibuf_get(s));
        return 1;
    }

    /* Wipe the string via delchar, testing ibuf_length simultaneously */
    while (ibuf_length(s) > 0) {
        ibuf_delchar(s);
    }

    /* Make sure s is now an empty string. */
    if (strcmp(ibuf_get(s), "") != 0) {
        debug("test_delchar: Expected empty string, got: %s\n", ibuf_get(s));
        return 2;
    }

    debug("test_delchar: Succeeded.\n");
    return 0;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
/* Updates the status bar */
static void update_status_win(enum win_refresh dorefresh)
{
    int pos;
    int attr;

    attr = hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR);

    /* Print white background */
    swin_wattron(status_win, attr);

    for (pos = 0; pos < WIDTH; pos++)
        swin_mvwprintw(status_win, 0, pos, " ");
    /* Show the user which window is focused */
    if (focus == GDB)
        swin_mvwprintw(status_win, 0, WIDTH - 1, "*");
    else if (focus == CGDB || focus == CGDB_STATUS_BAR)
        swin_mvwprintw(status_win, 0, WIDTH - 1, " ");

    swin_wattroff(status_win, attr);

    /* Print the regex that the user is looking for Forward */
    if (sbc_kind == SBC_REGEX && regex_direction_cur) {
        if_display_message("/", dorefresh, WIDTH - 1, "%s", ibuf_get(regex_cur));
        swin_curs_set(1);
    }
    /* Regex backwards */
    else if (sbc_kind == SBC_REGEX) {
        if_display_message("?", dorefresh, WIDTH - 1, "%s", ibuf_get(regex_cur));
        swin_curs_set(1);
    }
    /* A colon command typed at the status bar */
    else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_NORMAL) {
        const char *command = ibuf_get(cur_sbc);

        if (!command)
            command = "";
        if_display_message(":", dorefresh, WIDTH - 1, "%s", command);
        swin_curs_set(1);
    }
    /* Default: Current Filename */
    else {
        /* Print filename */
        const char *filename = source_current_file(src_viewer);

        if (filename) {
            if_display_message("", dorefresh, WIDTH - 1, "%s", filename);
        }
    }

    if (dorefresh == WIN_REFRESH)
        swin_wrefresh(status_win);
    else
        swin_wnoutrefresh(status_win);
}
static int test_addchar(ibuf s) {

    /* Add an exclamation to the hello world string. */
    ibuf_addchar(s, '!');

    /* Make sure it was added correctly. */
    if (strcmp(ibuf_get(s), "hello world!") != 0) {
        debug("test_addchar: Mismatch, expected \"hello world!\", got: %s\n",
                ibuf_get(s));
        return 1;
    }

    debug("test_addchar: Succeeded.\n");
    return 0;
}
Exemplo n.º 5
0
int Ctgdb::Process_console_command(tgdb_request_ptr request)
{
	struct ibuf *command;

	if (!request)
		return -1;

	if (!Can_issue_command())
		return -1;

	if (request->header != TGDB_REQUEST_CONSOLE_COMMAND)
		return -1;

	command = ibuf_init ();
	ibuf_add (command, request->choice.console_command.command);
	ibuf_addchar (command, '\n');

	if (Send(ibuf_get (command), TGDB_COMMAND_CONSOLE) == -1)
	{
		Logger_write_pos( __FILE__, __LINE__, "tgdb_send failed");
		return -1;
	}

	ibuf_free (command);
	command = NULL;

	return 0;
}
static int test_add(ibuf s) {

    /* Add the strings "hello" and " world" to the ibuf */
    ibuf_add(s, "hello");
    ibuf_add(s, " world");

    /* Make sure that's what got added */
    if (strcmp(ibuf_get(s), "hello world") != 0) {
        debug("test_add: Mismatch, expected \"hello world\", got: %s\n", 
                ibuf_get(s));
        return 1;
    }

    debug("test_add: Succeeded.\n");
    return 0;
}
Exemplo n.º 7
0
struct ibuf *ibuf_dup(struct ibuf *s)
{
    struct ibuf *ns = ibuf_init();

    ibuf_add(ns, ibuf_get(s));
    return ns;
}
Exemplo n.º 8
0
int highlight_node(const char *filename, struct buffer *buf)
{
    int ret;
    int length = 0;
    int lasttype = -1;
    struct ibuf *ibuf = ibuf_init();
    struct tokenizer *t = tokenizer_init();

    if (tokenizer_set_file(t, filename, buf->language) == -1) {
        if_print_message("%s:%d tokenizer_set_file error", __FILE__, __LINE__);
        return -1;
    }

    while ((ret = tokenizer_get_token(t)) > 0) {
        enum tokenizer_type e = tokenizer_get_packet_type(t);

        /*if_print_message  ( "TOKEN(%d:%s)\n", e, tokenizer_get_printable_enum ( e ) ); */

        if (e == TOKENIZER_NEWLINE) {
            sbpush(buf->tlines, strdup(ibuf_get(ibuf)));

            if (length > buf->max_width)
                buf->max_width = length;

            length = 0;
            lasttype = -1;
            ibuf_clear(ibuf);
        } else {
            const char *tok_data = tokenizer_get_data(t);
            enum hl_group_kind hlg = hlg_from_tokenizer_type(e, tok_data);

            if (hlg == HLG_LAST) {
                logger_write_pos(logger, __FILE__, __LINE__, "Bad hlg_type for '%s', e==%d\n", tok_data, e);
                hlg = HLG_TEXT;
            }

            /* Set the highlight group type */
            add_type(ibuf, &lasttype, hlg);
            /* Add the text and bump our length */
            length += ibuf_add(ibuf, tok_data);
        }
    }

    ibuf_free(ibuf);
    tokenizer_destroy(t);
    return 0;
}
Exemplo n.º 9
0
static void if_run_command(struct sviewer *sview, struct ibuf *ibuf_command)
{
    char *command = ibuf_get(ibuf_command);

    /* refresh and return if the user entered no data */
    if (ibuf_length(ibuf_command) == 0) {
        if_draw();
        return;
    }

    if (command_parse_string(command)) {
        if_display_message("Unknown command: ", 0, "%s", command);
    } else {
        update_status_win();
    }

    if_draw();
}
static int test_trim(ibuf s) {

    /* Test #1: Empty string. */
    ibuf_clear(s);
    ibuf_trim(s);
    if (strcmp(ibuf_get(s), "") != 0) {
        debug("test_trim: 1: expected empty string, got: %s\n", ibuf_get(s));
        return 1;
    }

    /* Test #2: Single space. */
    ibuf_clear(s);
    ibuf_addchar(s, ' ');
    ibuf_trim(s);
    if (strcmp(ibuf_get(s), "") != 0) {
        debug("test_trim: 2: expected empty string, got: %s\n", ibuf_get(s));
        return 2;
    }

    /* Test #3: "hello world" (no leading or trailing spaces) */
    ibuf_clear(s);
    ibuf_add(s, "hello world");
    ibuf_trim(s);
    if (strcmp(ibuf_get(s), "hello world") != 0) {
        debug("test_trim: 3: expected \"hello world\", got: %s\n",
                ibuf_get(s));
        return 3;
    }

    /* Test #4: "  hello world  \t" (leading and trailing spaces) */
    ibuf_clear(s);
    ibuf_add(s, "  hello world  \t");
    ibuf_trim(s);
    if (strcmp(ibuf_get(s), "hello world") != 0) {
        debug("test_trim: 4: expected \"hello world\", got: %s\n",
                ibuf_get(s));
        return 3;
    }

    debug("test_trim: Succeeded.\n");
    return 0;
}
Exemplo n.º 11
0
int Ctgdb::Send(char *command, enum tgdb_command_choice command_choice, ITarget* target)
{
	struct tgdb_command *tc;
	struct ibuf *temp_command = ibuf_init ();
	int length = strlen (command);

	/* Add a newline to the end of the command if it doesn't exist */
	ibuf_add (temp_command, command);

	if (command[length - 1] != '\n')
		ibuf_addchar (temp_command, '\n');

	/* Create the client command */
	tc = tgdb_command_create (ibuf_get (temp_command), command_choice, NULL);
	tc->ITarget = (void*) target;

	ibuf_free (temp_command);
	temp_command = NULL;

	if (Run_or_queue_command(tc) == -1)
	{
		Logger_write_pos( __FILE__, __LINE__,
				"tgdb_run_or_queue_command failed");
		return -1;
	}

	if (tgdb_client_tgdb_ran_command(tcc) == -1)
	{
		Logger_write_pos( __FILE__, __LINE__,
				"tgdb_client_tgdb_ran_command failed");
		return -1;
	}

	Process_client_commands();

	return 0;
}
Exemplo n.º 12
0
static int test_dup(ibuf s)
{

    ibuf t;

    /* Test duplicating a string. */
    ibuf_add(s, "test string 1");
    t = ibuf_dup(s);

    if (t == NULL) {
        debug("test_dup: ibuf_dup (attempt #1) returned NULL\n");
        return 1;
    }

    if (strcmp(ibuf_get(s), ibuf_get(t)) != 0) {
        debug("test_dup: Strings mismatched: \"%s\" != \"%s\"\n",
                ibuf_get(s), ibuf_get(t));
        return 1;
    }
    ibuf_free(t);

    /* Corner case: duplicate an empty string */
    ibuf_clear(s);
    t = ibuf_dup(s);

    if (t == NULL) {
        debug("test_dup: ibuf_dup (attempt #2) returned NULL\n");
        return 1;
    }

    if (strcmp(ibuf_get(t), "") != 0) {
        debug("test_dup: Expected empty string, got: %s\n", ibuf_get(t));
        return 1;
    }
    ibuf_free(t);

    debug("test_dup: Succeeded.\n");
    return 0;
}
int a2_handle_data(
		struct annotate_two *a2, struct state_machine *sm, 
		const char *data, const size_t size,
        char *gui_data, size_t *gui_size, 
		struct tgdb_list *command_list){
   int i, counter = 0;
   
   /* track state to find next file and line number */
   for(i = 0; i < size; ++i){
      switch(data[i]){
         /* Ignore all car returns outputted by gdb */
         case '\r':
            break;
         case '\n':     
            switch(sm->tgdb_state){
               case DATA:        
                  sm->tgdb_state = NEW_LINE;
                  break;
               case NEW_LINE:    
                  sm->tgdb_state = NEW_LINE;
                  data_process(a2, '\n', gui_data, &counter, command_list);    
                  break;
               case CONTROL_Z:   
                  sm->tgdb_state = DATA;
                  data_process(a2, '\n', gui_data, &counter, command_list);  
                  data_process(a2, '\032', gui_data, &counter, command_list);    
                  break;
               case ANNOTATION:  /* Found an annotation */
                  sm->tgdb_state = NL_DATA;
                  tgdb_parse_annotation(a2, ibuf_get ( sm->tgdb_buffer ), ibuf_length ( sm->tgdb_buffer ), command_list);
				  ibuf_clear ( sm->tgdb_buffer );
                  break;
               case NL_DATA:     
                  sm->tgdb_state = NEW_LINE;
                  break; 
               default:                                                       
                  logger_write_pos ( logger, __FILE__, __LINE__, "Bad state transition");
                  break;
            } /* end switch */
            break;
         case '\032':
            switch(sm->tgdb_state){
               case DATA:        
                  sm->tgdb_state = DATA;
                  data_process(a2, '\032', gui_data, &counter, command_list);  
                  break;
               case NEW_LINE:    
                  sm->tgdb_state = CONTROL_Z;          
                  break;
               case NL_DATA:     
                  sm->tgdb_state = CONTROL_Z;          
                  break;
               case CONTROL_Z:   
                  sm->tgdb_state = ANNOTATION;         
                  break;
               case ANNOTATION:  
				  ibuf_addchar ( sm->tgdb_buffer, data[i] );
                  break;
               default:                                                       
                  logger_write_pos ( logger, __FILE__, __LINE__, "Bad state transition");
                  break;
            } /* end switch */
            break;
         default:
            switch(sm->tgdb_state){
               case DATA:        
                  data_process(a2, data[i], gui_data, &counter, command_list);  
                  break;
               case NL_DATA:     
                  sm->tgdb_state = DATA;
                  data_process(a2, data[i], gui_data, &counter, command_list);  
                  break;
               case NEW_LINE:    
                  sm->tgdb_state = DATA;
                  data_process(a2, '\n', gui_data, &counter, command_list);     
                  data_process(a2, data[i], gui_data, &counter, command_list);  
                  break;
               case CONTROL_Z:   
                  sm->tgdb_state = DATA;
                  data_process(a2, '\n', gui_data, &counter, command_list);                 
                  data_process(a2, '\032', gui_data, &counter, command_list);                 
                  data_process(a2, data[i], gui_data, &counter, command_list);                 
                  break;
               case ANNOTATION:  
				  ibuf_addchar ( sm->tgdb_buffer, data[i] );
                  break;
               default:                                                       
                  logger_write_pos ( logger, __FILE__, __LINE__, "Bad state transition");
                  break;
            } /* end switch */
            break;
      } /* end switch */
   }  /* end for */

   gui_data[counter] = '\0';
   *gui_size = counter;
   return 0;
}
Exemplo n.º 14
0
/* source_input: Handles user input to the source window.
 * -------------
 *
 *   sview:     Source viewer object
 *   key:       Keystroke received.
 */
static void source_input(struct sviewer *sview, int key)
{
    switch (key) {
        case CGDB_KEY_UP:
        case 'k': {             /* VI-style up-arrow */
            int lineno = 1;
            cgdb_string_to_int(ibuf_get(G_line_number), &lineno);
            source_vscroll(sview, -lineno);
            break;
        }
        case CGDB_KEY_DOWN:
        case 'j': {             /* VI-style down-arrow */
            int lineno = 1;
            cgdb_string_to_int(ibuf_get(G_line_number), &lineno);
            source_vscroll(sview, lineno);
            break;
        }
        case CGDB_KEY_LEFT:
        case 'h':
            source_hscroll(sview, -1);
            break;
        case CGDB_KEY_RIGHT:
        case 'l':
            source_hscroll(sview, 1);
            break;
        case CGDB_KEY_CTRL_U:  /* VI-style 1/2 page up */
            source_vscroll(sview, -(get_src_height() / 2));
            break;
        case CGDB_KEY_PPAGE:
        case CGDB_KEY_CTRL_B:  /* VI-style page up */
            source_vscroll(sview, -(get_src_height() - 1));
            break;
        case CGDB_KEY_CTRL_D:  /* VI-style 1/2 page down */
            source_vscroll(sview, (get_src_height() / 2));
            break;
        case CGDB_KEY_NPAGE:
        case CGDB_KEY_CTRL_F:  /* VI-style page down */
            source_vscroll(sview, get_src_height() - 1);
            break;
        case 'g':              /* beginning of file */
            if (last_key_pressed == 'g')
                source_set_sel_line(sview, 1);
            break;
        case 'G': {              /* end of file or a line number */
            int lineno = -1;
            cgdb_string_to_int(ibuf_get(G_line_number), &lineno);
            source_set_sel_line(sview, lineno);
            break;
        }
        case '=':
            /* inc window by 1 */
            increase_win_height(0);
            break;
        case '-':
            /* dec window by 1 */
            decrease_win_height(0);
            break;
        case '+':
            increase_win_height(1);
            break;
        case '_':
            decrease_win_height(1);
            break;
        case 'o':
            /* Causes file dialog to be opened */
        {
            extern int kui_input_acceptable;

            kui_input_acceptable = 0;

            tgdb_request_inferiors_source_files(tgdb);
        }
            break;
        case ' ':
        {
            enum tgdb_breakpoint_action t = TGDB_BREAKPOINT_ADD;

            toggle_breakpoint(sview, t);
        }
            break;
        case 't':
        {
            enum tgdb_breakpoint_action t = TGDB_TBREAKPOINT_ADD;

            toggle_breakpoint(sview, t);
        }
            break;
        default:
            break;
    }

    /* Store digits into G_line_number for 'G' command. */
    if (key >= '0' && key <= '9') {
        ibuf_addchar(G_line_number, key);
    } else {
        ibuf_clear(G_line_number);
    }

    /* Some extended features that are set by :set sc */
    if_draw();
}
Exemplo n.º 15
0
/**
 * Send input to the CGDB source window.
 * 
 * @param key
 * The key to send to the CGDB source window.
 *
 * @param last_key
 * An output parameter. When set, that will tell cgdb to use the set value,
 * instead of the current key, as the "last_key_pressed" in the next
 * call to cgdb_input. This is useful to set mainly when the current input
 * has consumed more than one character, and the "last_key_pressed" should
 * be not set on the next call to cgdb_input.
 *
 * @return
 * Currently only returns 0.
 */
static int cgdb_input(int key, int *last_key)
{
    int regex_icase = cgdbrc_get_int(CGDBRC_IGNORECASE);

    if (src_viewer && src_viewer->cur) {
        int ret = 0;

        /* Handle setting (mX) and going ('X) to source buffer marks */
        if (last_key_pressed == 'm')
            ret = source_set_mark(src_viewer, key);
        else if (last_key_pressed == '\'')
            ret = source_goto_mark(src_viewer, key);

        if (ret) {
            /* When m[a-zA-Z] matches, don't let the marker char
             * be treated as the last key. That would allow the
             * chars mgg, to set the marker g, and then move to the top
             * of the file via gg.
             * CGDB should see those as mg (set a local mark g), and then
             * an individual g.
             */
            *last_key = 0;
            if_draw();
            return 0;
        }
    }

    switch (key) {
        case 's':
            gdb_scroller->in_scroll_mode = 1;
            if_set_focus(GDB);
            return 0;
        case 'i':
            if_set_focus(GDB);
            return 0;
        case ':':
            /* Set the type of the command the user is typing in the status bar */
            sbc_kind = SBC_NORMAL;
            if_set_focus(CGDB_STATUS_BAR);
            /* Since the user is about to type in a command, allocate a buffer
                         * in which this command can be stored. */
            cur_sbc = ibuf_init();
            return 0;
        case '/':
        case '?':
            if (src_viewer->cur) {
                regex_cur = ibuf_init();
                regex_direction_cur = ('/' == key);
                orig_line_regex = src_viewer->cur->sel_line;

                sbc_kind = SBC_REGEX;
                if_set_focus(CGDB_STATUS_BAR);

                /* Capturing regular expressions */
                source_search_regex_init(src_viewer);

                /* Initialize the function for finding a regex and tell user */
                if_draw();
            }
            return 0;
        case 'n':
            source_search_regex(src_viewer, ibuf_get(regex_last), 2,
                                regex_direction_last, regex_icase);
            if_draw();
            break;
        case 'N':
            source_search_regex(src_viewer, ibuf_get(regex_last), 2,
                                !regex_direction_last, regex_icase);
            if_draw();
            break;
        case CGDB_KEY_CTRL_T:
            if (tgdb_tty_new(tgdb) == -1) {
                /* Error */
            } else {
                if_layout();
            }

            break;
        case CGDB_KEY_CTRL_W:
            switch (cur_split_orientation) {
                case WSO_HORIZONTAL:
                    cur_split_orientation = WSO_VERTICAL;
                    break;
                case WSO_VERTICAL:
                    cur_split_orientation = WSO_HORIZONTAL;
                    break;
            }

            if_layout();

            break;
        case CGDB_KEY_F1:
            if_display_help();
            return 0;
        case CGDB_KEY_F5:
            /* Issue GDB run command */
            tgdb_request_run_debugger_command(tgdb, TGDB_RUN);
            return 0;
        case CGDB_KEY_F6:
            /* Issue GDB continue command */
            tgdb_request_run_debugger_command(tgdb, TGDB_CONTINUE);
            return 0;
        case CGDB_KEY_F7:
            /* Issue GDB finish command */
            tgdb_request_run_debugger_command(tgdb, TGDB_FINISH);
            return 0;
        case CGDB_KEY_F8:
            /* Issue GDB next command */
            tgdb_request_run_debugger_command(tgdb, TGDB_NEXT);
        case CGDB_KEY_F10:
            /* Issue GDB step command */
            tgdb_request_run_debugger_command(tgdb, TGDB_STEP);
            return 0;
        case CGDB_KEY_CTRL_L:
            if_layout();
            return 0;
    }

    source_input(src_viewer, key);
    return 0;
}
Exemplo n.º 16
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 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;
}
Exemplo n.º 17
0
/* Updates the status bar */
static void update_status_win(void)
{
    int pos;
    char filename[FSUTIL_PATH_MAX];
    int attr;

    if (hl_groups_get_attr(hl_groups_instance, HLG_STATUS_BAR, &attr) == -1)
        return;

    /* Update the tty status bar */
    if (tty_win_on) {
        wattron(tty_status_win, attr);
        for (pos = 0; pos < WIDTH; pos++)
            mvwprintw(tty_status_win, 0, pos, " ");

        mvwprintw(tty_status_win, 0, 0, (char *) tgdb_tty_name(tgdb));
        wattroff(tty_status_win, attr);
    }

    /* Print white background */
    wattron(status_win, attr);
    for (pos = 0; pos < WIDTH; pos++)
        mvwprintw(status_win, 0, pos, " ");
    if (tty_win_on)
        wattron(tty_status_win, attr);
    /* Show the user which window is focused */
    if (focus == GDB)
        mvwprintw(status_win, 0, WIDTH - 1, "*");
    else if (focus == TTY && tty_win_on)
        mvwprintw(tty_status_win, 0, WIDTH - 1, "*");
    else if (focus == CGDB || focus == CGDB_STATUS_BAR)
        mvwprintw(status_win, 0, WIDTH - 1, " ");
    wattroff(status_win, attr);
    if (tty_win_on)
        wattroff(tty_status_win, attr);

    /* Print the regex that the user is looking for Forward */
    if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_REGEX
            && regex_direction_cur) {
        if_display_message("/", WIDTH - 1, "%s", ibuf_get(regex_cur));
        curs_set(1);
    }
    /* Regex backwards */
    else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_REGEX) {
        if_display_message("?", WIDTH - 1, "%s", ibuf_get(regex_cur));
        curs_set(1);
    }
    /* A colon command typed at the status bar */
    else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_NORMAL) {
        char *command = ibuf_get(cur_sbc);

        if (!command)
            command = "";
        if_display_message(":", WIDTH - 1, "%s", command);
        curs_set(1);
    }
    /* Default: Current Filename */
    else {
        /* Print filename */
        if (src_win != NULL && source_current_file(src_win, filename) != NULL)
            if_display_message("", WIDTH - 1, "%s", filename);
    }

    wrefresh(status_win);
}
Exemplo n.º 18
0
int internal_if_input(int key)
{
    int regex_icase = cgdbrc_get(CGDBRC_IGNORECASE)->variant.int_val;

    /* Normally, CGDB_KEY_ESC, but can be configured by the user */
    int cgdb_mode_key = cgdbrc_get(CGDBRC_CGDB_MODE_KEY)->variant.int_val;

    /* The cgdb mode key, puts the debugger into command mode */
    if (focus != CGDB && key == cgdb_mode_key) {
        /* Depending on which cgdb was in, it can free some memory here that
         * it was previously using. */
        if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_NORMAL) {
            ibuf_free(cur_sbc);
            cur_sbc = NULL;
        } else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_REGEX) {
            ibuf_free(regex_cur);
            regex_cur = NULL;
            free(src_win->cur->buf.cur_line);
            src_win->cur->buf.cur_line = NULL;
            src_win->cur->sel_rline = orig_line_regex;
            src_win->cur->sel_line = orig_line_regex;
        }
        if_set_focus(CGDB);
        return 0;
    }
    /* If you are already in cgdb mode, the cgdb mode key does nothing */
    else if (key == cgdb_mode_key)
        return 0;

    /* Check for global keystrokes */
    switch (focus) {
        case CGDB:
            switch (key) {
                case 'i':
                    if_set_focus(GDB);
                    return 0;
                case 'I':
                    if_set_focus(TTY);
                    return 0;
                case ':':
                    /* Set the type of the command the user is typing in the status bar */
                    sbc_kind = SBC_NORMAL;
                    if_set_focus(CGDB_STATUS_BAR);
                    /* Since the user is about to type in a command, allocate a buffer 
                     * in which this command can be stored. */
                    cur_sbc = ibuf_init();
                    return 0;
                case '/':
                case '?':
                    if (src_win->cur != NULL) {
                        regex_cur = ibuf_init();
                        regex_direction_cur = ('/' == key);
                        orig_line_regex = src_win->cur->sel_line;

                        sbc_kind = SBC_REGEX;
                        if_set_focus(CGDB_STATUS_BAR);

                        /* Capturing regular expressions */
                        source_search_regex_init(src_win);

                        /* Initialize the function for finding a regex and tell user */
                        if_draw();
                    }
                    return 0;
                case 'n':
                    source_search_regex(src_win, ibuf_get(regex_last), 2,
                            regex_direction_last, regex_icase);
                    if_draw();
                    break;
                case 'N':
                    source_search_regex(src_win, ibuf_get(regex_last), 2,
                            !regex_direction_last, regex_icase);
                    if_draw();
                    break;
                case 'T':
                    if (tty_win_on) {
                        tty_win_on = 0;
                        focus = CGDB;
                    } else {
                        tty_win_on = 1;
                        focus = TTY;
                    }

                    if_layout();

                    break;
                case CGDB_KEY_CTRL_T:
                    if (tgdb_tty_new(tgdb) == -1) {
                        /* Error */
                    } else {
                        scr_free(tty_win);
                        tty_win = NULL;
                        if_layout();
                    }

                    break;
                case CGDB_KEY_F1:
                    if_display_help();
                    return 0;
                case CGDB_KEY_F5:
                    /* Issue GDB run command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb, TGDB_RUN);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F6:
                    /* Issue GDB continue command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb,
                            TGDB_CONTINUE);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F7:
                    /* Issue GDB finish command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb,
                            TGDB_FINISH);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F8:
                    /* Issue GDB next command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb, TGDB_NEXT);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F10:
                    /* Issue GDB step command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb, TGDB_STEP);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_CTRL_L:
                    if_layout();
                    return 0;
            }
            source_input(src_win, key);
            return 0;
            break;
        case TTY:
            return tty_input(key);
        case GDB:
            return gdb_input(key);
        case FILE_DLG:
        {
            static char filedlg_file[MAX_LINE];
            int ret = filedlg_recv_char(fd, key, filedlg_file);

            /* The user cancelled */
            if (ret == -1) {
                if_set_focus(CGDB);
                return 0;
                /* Needs more data */
            } else if (ret == 0) {
                return 0;
                /* The user picked a file */
            } else if (ret == 1) {
                tgdb_request_ptr request_ptr;

                request_ptr = tgdb_request_filename_pair(tgdb, filedlg_file);
                handle_request(tgdb, request_ptr);
                if_set_focus(CGDB);
                return 0;
            }
        }
            return 0;
        case CGDB_STATUS_BAR:
            return status_bar_input(src_win, key);
    }

    /* Never gets here */
    return 0;
}
Exemplo n.º 19
0
/* gdb_input: Handles user input to the GDB window.
 * ----------
 *
 *   key:  Keystroke received.
 *
 * Return Value:    0 if internal key was used, 
 *                  1 if input to gdb or ...
 *                  -1        : Error resizing terminal -- terminal too small
 */
static int gdb_input(int key, int *last_key)
{
    int result = 0;

    if (gdb_scroller->in_search_mode)
        return gdb_input_regex_input(gdb_scroller, key);

    if (gdb_scroller->in_scroll_mode) {

        /* Handle setting (mX) and going ('X) to gdb buffer marks */
        if (last_key_pressed == 'm' || last_key_pressed == '\'') {
            int ret = 0;

            if (last_key_pressed == 'm')
                ret = scr_set_mark(gdb_scroller, key);
            else if(last_key_pressed == '\'')
                ret = scr_goto_mark(gdb_scroller, key);

            if (ret) {
                *last_key = 0;
                if_draw();
            }
            return 0;
        }

        /* In scroll mode, all extra characters are not passed to
         * the active GDB command. result = 0 above ensures that. */
        switch (key) {
            
            case 'm':
            case '\'':
                /* Mark keys - ignore them */
                break;
            case CGDB_KEY_CTRL_U:
                scr_up(gdb_scroller, get_gdb_height() / 2);
                break;
            case CGDB_KEY_PPAGE:
                scr_up(gdb_scroller, get_gdb_height() - 1);
                break;
            case CGDB_KEY_CTRL_D:
                scr_down(gdb_scroller, get_gdb_height() / 2);
                break;
            case CGDB_KEY_NPAGE:
                scr_down(gdb_scroller, get_gdb_height() - 1);
                break;
            case CGDB_KEY_HOME:
            case CGDB_KEY_F11:
                scr_home(gdb_scroller);
                break;
            case 'G':
            case CGDB_KEY_END:
            case CGDB_KEY_F12:
                scr_end(gdb_scroller);
                break;
            case 'k':
            case CGDB_KEY_UP:
            case CGDB_KEY_CTRL_P:
                scr_up(gdb_scroller, 1);
                break;
            case 'j':
            case CGDB_KEY_DOWN:
            case CGDB_KEY_CTRL_N:
                scr_down(gdb_scroller, 1);
                break;
            case 'g':
                if (last_key_pressed == 'g') {
                    scr_home(gdb_scroller);
                }
                break;
            case 'q':
            case 'i':
            case '\r':
            case '\n':
            case CGDB_KEY_CTRL_M:
                scr_end(gdb_scroller);
                gdb_scroller->in_scroll_mode = 0;
                break;
            case 'n':
                scr_search_regex(gdb_scroller, ibuf_get(regex_last), 2,
                    regex_direction_last, cgdbrc_get_int(CGDBRC_IGNORECASE));
                break;
            case 'N':
                scr_search_regex(gdb_scroller, ibuf_get(regex_last), 2,
                    !regex_direction_last, cgdbrc_get_int(CGDBRC_IGNORECASE));
                break;
            case '/':
            case '?':
                /* Capturing regular expressions */
                regex_cur = ibuf_init();
                regex_direction_cur = ('/' == key);
                orig_line_regex = gdb_scroller->current.r;

                sbc_kind = SBC_REGEX;

                scr_search_regex_init(gdb_scroller);
                break;
        }

    } else {
        switch (key) {
            case CGDB_KEY_PPAGE:
                scr_up(gdb_scroller, get_gdb_height() - 1);
                break;
            case CGDB_KEY_CTRL_L:
                scr_clear(gdb_scroller);

                /* The return 1 tells readline that gdb did not handle the
                 * Ctrl-l. That way readline will handle it. Because
                 * readline uses TERM=dumb, that means that it will clear
                 * a single line and put out the prompt. */
                result = 1;
                break;
            default:
                /* This tells the input to go to active GDB command */
                result = 1;
        }
    }

    if_draw();

    return result;
}
Exemplo n.º 20
0
Arquivo: cgdb.c Projeto: i4fumi/cgdb
/* Please forgive me for adding all the comment below. This function
 * has some strange bahaviors that I thought should be well explained.
 */
void rlctx_send_user_command(char *line)
{
    char *cline;
    int length;
    char *rline_prompt;
    tgdb_request_ptr request_ptr;

    if (line == NULL) {
        /* NULL line means rl_callback_read_char received EOF */
        ibuf_add(current_line, "quit");
    } else {
        /* Add the line passed in to the current line */
        ibuf_add(current_line, line);
    }

    /* Get current line, and current line length */
    cline = ibuf_get(current_line);
    length = ibuf_length(current_line);

    /* Check to see if the user is escaping the line, to use a 
     * multi line command. If so, return so that the user can
     * continue the command. This data should not go into the history
     * buffer, or be sent to gdb yet. 
     *
     * Also, notice the length > 0 condition. (length == 0) can happen 
     * when the user simply hits Enter on the keyboard. */
    if (length > 0 && cline[length - 1] == '\\') {
        /* The \ char is for continuation only, it is not meant to be sent
         * to GDB as a character. */
        ibuf_delchar(current_line);

        /* Only need to change the prompt the first time the \ char is used.
         * Doing it a second time would erase the real rline_last_prompt,
         * since the prompt has already been set to "".
         */
        if (!rline_last_prompt) {
            rline_get_prompt(rline, &rline_prompt);
            rline_last_prompt = strdup(rline_prompt);
            /* GDB set's the prompt to nothing when doing continuation.
             * This is here just for compatibility. */
            rline_set_prompt(rline, "");
        }

        return;
    }

    /* If here, a full command has been sent. Restore the prompt. */
    if (rline_last_prompt) {
        rline_set_prompt(rline, rline_last_prompt);
        free(rline_last_prompt);
        rline_last_prompt = NULL;
    }

    /* Don't add the enter command to the history */
    if (length > 0)
        rline_add_history(rline, cline);

    request_ptr = tgdb_request_run_console_command(tgdb, cline);
    if (!request_ptr)
        logger_write_pos(logger, __FILE__, __LINE__,
                "rlctx_send_user_command\n");

    /* Send this command to TGDB */
    handle_request(tgdb, request_ptr);

    ibuf_clear(current_line);
}
Exemplo n.º 21
0
int filedlg_recv_char(struct filedlg *fd, int key, char *file, int last_key_pressed)
{
    /* Initialize size variables */
    int height = swin_getmaxy(fd->win);

    filedlg_display(fd);

    switch (key) {
        case 'q':
            return -1;
            /* Vertical scrolling */
        case CGDB_KEY_DOWN:
        case 'j':
            filedlg_vscroll(fd, 1);
            break;
        case CGDB_KEY_NPAGE:
        case CGDB_KEY_CTRL_F:  /* VI-style page down */
            filedlg_vscroll(fd, height - 1);
            break;
        case CGDB_KEY_CTRL_D:  /* VI-style 1/2 page down */
            filedlg_vscroll(fd, height / 2);
            break;
        case CGDB_KEY_CTRL_U:  /* VI-style 1/2 page up */
            filedlg_vscroll(fd, -height / 2);
            break;
        case CGDB_KEY_UP:
        case 'k':
            filedlg_vscroll(fd, -1);
            break;
        case CGDB_KEY_PPAGE:
        case CGDB_KEY_CTRL_B:  /* VI-style page up */
            filedlg_vscroll(fd, -(height - 1));
            break;
            /* Horizontal scrolling */
        case CGDB_KEY_RIGHT:
        case 'l':
            filedlg_hscroll(fd, 1);
            break;
        case CGDB_KEY_LEFT:
        case 'h':
            filedlg_hscroll(fd, -1);
            break;
        case '/':
        case '?':
            regex_direction = ('/' == key);

            /* Capturing regular expressions */
            filedlg_search_regex_init(fd);
            capture_regex(fd);
            break;
        case 'n':
            filedlg_search_regex(fd, regex_line, 2, regex_direction, 1);
            break;
        case 'N':
            filedlg_search_regex(fd, regex_line, 2, !regex_direction, 1);
            break;
            /* User selected a file */
        case '\n':
        case '\r':
        case CGDB_KEY_CTRL_M:
            strcpy(file, fd->buf->files[fd->buf->sel_line]);
            return 1;

        case 'g':              /* beginning of file */
            if (last_key_pressed == 'g')
                filedlg_set_sel_line(fd, 0);
            break;
        case 'G': {             /* end of file, or a line number*/
            int lineno = -1, result;
            result = cgdb_string_to_int(ibuf_get(fd->G_line_number), &lineno);
            if (result == 0) {
                filedlg_set_sel_line(fd, lineno -1);
            }
            break;
        }
        default:
            break;
    }

    /* Store digits into G_line_number for 'G' command. */
    if (key >= '0' && key <= '9') {
        ibuf_addchar(fd->G_line_number, key);
    } else {
        ibuf_clear(fd->G_line_number);
    }

    filedlg_display(fd);

    return 0;
}
Exemplo n.º 22
0
static int highlight_node ( struct list_node *node ) {
    struct tokenizer *t = tokenizer_init ();
    int ret;
    struct ibuf *ibuf = ibuf_init ();
    ibuf_addchar ( ibuf, HL_CHAR );
    ibuf_addchar ( ibuf, HLG_TEXT );

    /* Initialize */
    node->buf.length = 0;
    node->buf.tlines = NULL;
    node->buf.max_width = 0;

    if ( tokenizer_set_file ( t, node->path, node->language ) == -1 ) {
        if_print_message ("%s:%d tokenizer_set_file error", __FILE__, __LINE__);
        return -1;
    }

    while ( ( ret = tokenizer_get_token ( t ) ) > 0 ) {
        enum tokenizer_type e = tokenizer_get_packet_type ( t );
        /*if_print_message  ( "TOKEN(%d:%s)\n", e, tokenizer_get_printable_enum ( e ) );*/

        switch ( e ) {
        case TOKENIZER_KEYWORD:
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_KEYWORD );
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_TEXT );
            break;
        case TOKENIZER_TYPE:
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_TYPE );
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_TEXT );
            break;
        case TOKENIZER_LITERAL:
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_LITERAL );
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_TEXT );
            break;
        case TOKENIZER_NUMBER:
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            break;
        case TOKENIZER_COMMENT:
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_COMMENT );
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_TEXT );
            break;
        case TOKENIZER_DIRECTIVE:
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_DIRECTIVE );
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_TEXT );
            break;
        case TOKENIZER_TEXT:
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            break;
        case TOKENIZER_NEWLINE:
            node->buf.length++;
            node->buf.tlines = realloc ( node->buf.tlines, sizeof ( char *) * node->buf.length );
            node->buf.tlines[node->buf.length-1] = strdup ( ibuf_get ( ibuf ) );

            if ( ibuf_length ( ibuf ) > node->buf.max_width )
                node->buf.max_width = ibuf_length ( ibuf );

            ibuf_clear ( ibuf );
            ibuf_addchar ( ibuf, HL_CHAR );
            ibuf_addchar ( ibuf, HLG_TEXT );
            break;
        case TOKENIZER_ERROR:
            ibuf_add ( ibuf, tokenizer_get_data ( t ) );
            break;
        default:
            return -1;
            break;
        }
    }

    return 0;
}