Ejemplo n.º 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;
}
Ejemplo n.º 2
0
static void add_type(struct ibuf *ibuf, int *lasttype, int newtype)
{
    /* Add HL_CHAR + HLG_* token only if the HLG_ type has changed */
    if ( *lasttype != newtype ) {
        ibuf_addchar(ibuf, HL_CHAR);
        ibuf_addchar(ibuf, newtype);
        *lasttype = newtype;
    }
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
void ibuf_add(struct ibuf *s, const char *d)
{
    int length = strlen(d), i;

    for (i = 0; i < length; i++)
        ibuf_addchar(s, d[i]);
}
Ejemplo n.º 5
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;
}
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;
}
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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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();
}
Ejemplo n.º 12
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;
}
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;
}