예제 #1
0
struct hl_line_attr *hl_regex_highlight(struct hl_regex_info **info,
        char *line, enum hl_group_kind group_kind)
{
    hl_line_attr *attrs = NULL;

    if (*info && (*info)->regex && (*info)->regex[0]) {
        int pos = 0;

        for (;;) {
            int ret;
            int len;
            int start, end;

            ret = hl_regex_search(info, line + pos, (*info)->regex, (*info)->icase, &start, &end);
            if (ret <= 0)
                break;

            len = end - start;
            pos += start;

            /* Push search attribute */
            sbpush(attrs, hl_line_attr(pos, group_kind));

            /* And the back to regular text attribute */
            sbpush(attrs, hl_line_attr(pos + len, 0));

            pos += len;
        }
    }

    return attrs;
}
예제 #2
0
파일: sources.cpp 프로젝트: lizh06/cgdb
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;
}
예제 #3
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;
}
예제 #4
0
파일: filedlg.cpp 프로젝트: ibuclaw/cgdb
static int filedlg_search_regex(struct filedlg *fd, const char *regex,
        int opt, int direction, int icase)
{
    if (!fd || !fd->buf)
        return -1;

    if (regex && regex[0]) {
        int line;
        int line_end;
        int line_inc = direction ? +1 : -1;
        int line_start = fd->buf->sel_rline;

        line = wrap_line(fd->buf, 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(fd->buf->files) - 1;
        }

        for(;;) {
            int ret;
            int start, end;
            char *file = fd->buf->files[line];

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

                /* Finalized match - move to this location */
                if (opt == 2) {
                    fd->buf->sel_rline = line;
                    fd->last_hlregex = fd->hlregex;
                    fd->hlregex = 0;
                }
                return 1;
            }

            line = wrap_line(fd->buf, line + line_inc);
            if (line == line_end)
                break;
        }
    }

    /* Nothing found - go back to original line */
    fd->buf->sel_line = fd->buf->sel_rline;
    return 0;
}