Exemplo n.º 1
0
void scr_free(struct scroller *scr)
{
    int i;

    /* Release the buffer */
    for (i = 0; i < sbcount(scr->lines); i++) {
        free(scr->lines[i].line);
        sbfree(scr->lines[i].attrs);
    }
    sbfree(scr->lines);
    scr->lines = NULL;

    hl_regex_free(&scr->last_hlregex);
    scr->last_hlregex = NULL;
    hl_regex_free(&scr->hlregex);
    scr->hlregex = NULL;

    free(scr->last_inferior_line);
    scr->last_inferior_line = NULL;

    swin_delwin(scr->win);
    scr->win = NULL;

    /* Release the scroller object */
    free(scr);
}
Exemplo n.º 2
0
void source_free(struct sviewer *sview)
{
    /* Free all file buffers */
    while (sview->list_head)
        source_del(sview, sview->list_head->path);

    hl_regex_free(&sview->hlregex);
    sview->hlregex = NULL;
    hl_regex_free(&sview->last_hlregex);
    sview->last_hlregex = NULL;

    swin_delwin(sview->win);
    sview->win = NULL;

    free(sview);
}
Exemplo n.º 3
0
int source_search_regex(struct sviewer *sview,
        const char *regex, int opt, int direction, int icase)
{
    struct list_node *node = sview ? sview->cur : NULL;

    if (!node)
        return -1;

    if (regex && *regex) {
        int line;
        int line_end;
        int line_inc = direction ? +1 : -1;
        int line_start = node->sel_rline;

        line = wrap_line(node, line_start + line_inc);

        if (cgdbrc_get_int(CGDBRC_WRAPSCAN))
        {
            // Wrapping is on so stop at the line we started on.
            line_end = line_start;
        }
        else
        {
            // No wrapping. Stop at line 0 if searching down and last line
            // if searching up.
            line_end = direction ? 0 : sbcount(node->file_buf.lines) - 1;
        }

        for(;;) {
            int ret;
            int start, end;
            char *line_str = node->file_buf.lines[line].line;

            ret = hl_regex_search(&sview->hlregex, line_str, regex, icase, &start, &end);
            if (ret > 0) {
                /* Got a match */
                node->sel_line = line;

                /* Finalized match - move to this location */
                if (opt == 2) {
                    node->sel_rline = line;

                    hl_regex_free(&sview->last_hlregex);
                    sview->last_hlregex = sview->hlregex;
                    sview->hlregex = 0;
                }
                return 1;
            }

            line = wrap_line(node, line + line_inc);
            if (line == line_end)
                break;
        }
    }

    /* Nothing found - go back to original line */
    node->sel_line = node->sel_rline;
    return 0;
}
Exemplo n.º 4
0
int scr_search_regex(struct scroller *scr, const char *regex, int opt,
    int direction, int icase)
{
    if (regex && *regex) {
        int line;
        int line_end;
        int line_inc = direction ? +1 : -1;
        int line_start = scr->search_r;

        line = wrap_line(scr, line_start + line_inc);

        if (cgdbrc_get_int(CGDBRC_WRAPSCAN))
        {
            // Wrapping is on so stop at the line we started on.
            line_end = line_start;
        }
        else
        {
            // No wrapping. Stop at line 0 if searching down and last line
            // if searching up.
            line_end = direction ? 0 : sbcount(scr->lines) - 1;
        }

        for (;;)
        {
            int ret;
            int start, end;
            char *line_str = scr->lines[line].line;

            ret = hl_regex_search(&scr->hlregex, line_str, regex, icase, &start, &end);
            if (ret > 0)
            {
                /* Got a match */
                scr->current.r = line;
                scr->current.c = get_last_col(scr, line);

                /* Finalized match - move to this location */
                if (opt == 2) {
                    scr->search_r = line;

                    hl_regex_free(&scr->hlregex);
                    scr->last_hlregex = scr->hlregex;
                    scr->hlregex = 0;
                }
                return 1;
            }

            line = wrap_line(scr, line + line_inc);
            if (line == line_end)
                break;
        }
    }

    /* Nothing found - go back to original line */
    scr->current.r = scr->search_r;
    scr->current.c = get_last_col(scr, scr->search_r);
    return 0;
}
Exemplo n.º 5
0
void filedlg_free(struct filedlg *fdlg)
{
    filedlg_clear(fdlg);

    hl_regex_free(&fdlg->last_hlregex);
    fdlg->last_hlregex = NULL;

    hl_regex_free(&fdlg->hlregex);
    fdlg->hlregex = NULL;

    swin_delwin(fdlg->win);
    fdlg->win = NULL;

    free(fdlg->buf);
    fdlg->buf = NULL;

    delete fdlg;
}
Exemplo n.º 6
0
void filedlg_free(struct filedlg *fdlg)
{
    filedlg_clear(fdlg);

    ibuf_free(fdlg->G_line_number);

    hl_regex_free(&fdlg->last_hlregex);
    fdlg->last_hlregex = NULL;

    hl_regex_free(&fdlg->hlregex);
    fdlg->hlregex = NULL;

    swin_delwin(fdlg->win);
    fdlg->win = NULL;

    free(fdlg->buf);
    fdlg->buf = NULL;

    free(fdlg);
}
Exemplo n.º 7
0
int internal_if_input(int key, int *last_key)
{
    /* Normally, CGDB_KEY_ESC, but can be configured by the user */
    int cgdb_mode_key = cgdbrc_get_int(CGDBRC_CGDB_MODE_KEY);

    /* The cgdb mode key, puts the debugger into command mode */
    if (focus != CGDB && key == cgdb_mode_key) {
        enum Focus new_focus = CGDB;

        /* 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;

            hl_regex_free(&src_viewer->hlregex);

            src_viewer->cur->sel_rline = orig_line_regex;
            src_viewer->cur->sel_line = orig_line_regex;
            sbc_kind = SBC_NORMAL;
        }
        else if (focus == GDB && sbc_kind == SBC_REGEX)
        {
            ibuf_free(regex_cur);
            regex_cur = NULL;

            gdb_scroller->in_search_mode = 0;
            sbc_kind = SBC_NORMAL;

            new_focus = GDB;
        }

        if_set_focus(new_focus);
        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:
            return cgdb_input(key, last_key);
        case GDB:
            return gdb_input(key, last_key);
        case FILE_DLG:
        {
            char filedlg_file[MAX_LINE];
            int ret = filedlg_recv_char(fd, key, filedlg_file, last_key_pressed);

            /* 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) {
                if_show_file(filedlg_file, 0, 0);
                if_set_focus(CGDB);
                return 0;
            }
        }
            return 0;
        case CGDB_STATUS_BAR:
            return status_bar_input(src_viewer, key);
    }

    /* Never gets here */
    return 0;
}
Exemplo n.º 8
0
int hl_regex_search(struct hl_regex_info **info, char *line,
    const char *regex, int icase, int *start, int *end)
{
    int result;
    regmatch_t pmatch;
    int recompile = 0;

    *start = -1;
    *end = -1;

    if (!regex || !regex[0])
        return -1;
    
    if (!*info) {
        *info = (struct hl_regex_info *)cgdb_calloc(1, sizeof(struct hl_regex_info));
        recompile = 1;
    } 
    else if (!(*info)->regex)
        recompile = 1;
    else if ((*info)->regex == regex)
        recompile = 0;
    else if ((icase != -1) && (icase != (*info)->icase))
        recompile = 1;
    else if (strcmp(regex, (*info)->regex))
        recompile = 1;

    if (recompile) {
        if (*info && (*info)->regex) {
            regfree(&(*info)->t);

            free((*info)->regex);
            (*info)->regex = NULL;
        }

        /* Compile the regular expression */
        if (regcomp(&(*info)->t, regex, REG_EXTENDED | (icase ? REG_ICASE : 0)) != 0) {
            hl_regex_free(info);
            return -1;
        }

        (*info)->regex = strdup(regex);
        (*info)->icase = icase;
    }

    char *lf = strchr(line, '\n');
    if (lf)
        *lf = '\0';

    result = regexec(&(*info)->t, line, 1, &pmatch, 0);

    if (lf)
        *lf = '\n';

    if ((result == 0) && (pmatch.rm_eo > pmatch.rm_so)) {
        *start = pmatch.rm_so;
        *end = pmatch.rm_eo;
        return 1;
    }

    return 0;
}