Пример #1
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;
}
Пример #2
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;
}
Пример #3
0
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;
}
Пример #4
0
/* -------------------------------------------------- */
static int add_data(int fd, char *buff, int len)
{
int rc, idx;

if (!buff) {
	char pipo[] = ".\r\n\0";
	wrap_line(fd, NULL, 0); /* flush */
	return wrap_write(fd, pipo, 3); /* writable strings ... avoid . -> .. */
	}
if (len <= 0) len = strlen(buff);

for (idx=0; idx < len; idx += rc) {
	rc = wrap_line(fd, buff+idx, len - idx);
	if (rc < 0) {close(fd); return -1; }
	}

return idx;
}
Пример #5
0
/* -------------------------------------------------- */
static int add_header(int fd, const char *name, const char *value)
{
int rc;
char buff[1024];

#if (WANT_DEBUG &4)
fprintf(stderr,"[Add_header(%s,%s)]\n", name?name :"Null", value?value:"Null");
#endif

if (name) rc = sprintf(buff, "%s: %s\n", name, value);
else memcpy(buff, "\n", rc = 1);
rc = wrap_line(fd, buff, rc);
if (rc < 0) {close(fd); return -1; }

return rc;
}
Пример #6
0
/* -------------------------------------------------- */
static int do_ping_pong(int fd, char *buff, int len)
{
int err=0,done;

char temp[1024] ;

#if (WANT_DEBUG &4)
fprintf(stderr,"[do_ping_pong(%s,%d)]\n", buff?buff:"NULL", len);
#endif
if (buff && len) {
	done = wrap_line(fd, buff, len);
	if (done < 0) {close(fd); goto quit; }
	}

for (err=done=0; 1 ; done += len) {
	len = wrap_read(fd, temp+done, sizeof temp -done);
	if (len <= 0) {close(fd); err = -1; goto quit; }
#if (WANT_DEBUG &2)
	temp[done+len] = 0;
	fprintf(stderr," [PartRead{%d+%d}{%02x|%02x}:\"%s\"]\n"
	, done,len, temp[3], temp[done+len-1], temp+done);
#endif
	if (done+len < 3) continue;
	if (temp[0] != '2') {err = '0' - temp[0]; break; }
	if (temp[done+len-1] == '\n') {
		if (temp[3] == '-') { done = 0; len = 0; continue; }
		else { break; }
		}
	else { done = 4; len = 0; }
	}

quit:
#if (WANT_DEBUG &4)
fprintf(stderr,"[Do_ping_pong(%s) err=%d done=%d] :\"%s\"]\n"
, buff, err, done, temp);
#endif
return (err) ? err : done;
}
Пример #7
0
Файл: cmds.c Проект: hankem/jed
/*{{{ ins_char_cmd */
int ins_char_cmd (void)
{
   unsigned char ch;
   int wrap = Buffer_Local.wrap_column;
   int do_blink;
   int did_abbrev = 0;
   SLang_Name_Type *wrapok_hook;

   CHECK_READ_ONLY
#if 0
     ;
#endif
#if JED_HAS_LINE_ATTRIBUTES
   if (check_line_attr_no_modify (CLine))
     return 0;
#endif

   ch = SLang_Last_Key_Char;

   if (ch == '\n')
     {
	newline();
	return(1);
     }

#if JED_HAS_ABBREVS
   if (CBuf->flags & ABBREV_MODE)
     {
	if (-1 == (did_abbrev = jed_expand_abbrev (ch)))
	  return -1;
     }
#endif

   if ((CBuf->flags & OVERWRITE_MODE) && !eolp())
     {
	/* FIXME: jed_del_wchar should be called for the last byte of a
	 * UTF-8 sequence
	 */
	if ((did_abbrev == 0)
	    && (-1 == jed_del_wchar ()))
	  return -1;
     }

   /* It is ok to use Point as an estimator of the current column.  This
    * avoids the more expensive call to calculate_column.
    */
   if (CBuf->buffer_hooks != NULL)
     wrapok_hook = CBuf->buffer_hooks->wrapok_hook;
   else
     wrapok_hook = NULL;

   if (((ch == ' ') || (Point >= wrap))
       && ((CBuf->modes & WRAP_MODE) || (wrapok_hook != NULL))
       && (calculate_column() > wrap)
       && ((wrapok_hook == NULL)
	   || (1 == execute_is_ok_hook (wrapok_hook))))
     {
	unsigned int this_line_num = LineNum;

	if ((did_abbrev == 0)
	    && (-1 == jed_insert_byte (ch)))
	  return -1;

	if (1 != wrap_line(0))	       /* do not format--- just wrap */
	  return -1;		       /* line isn't wrapable */

	/* There is a bug involving wrapping a very long line containing
	 * no whitespace and then we try to insert a character.  This work
	 * arounds the bug.
	 */
	if ((this_line_num == LineNum)
	    && (ch == ' '))
	    /* && (calculate_column () > wrap)) */
	  {
	     if (0 == jed_right (1))
	       newline ();
	  }

	if ((CBuf->buffer_hooks != NULL)
	    && (CBuf->buffer_hooks->wrap_hook != NULL))
	  SLexecute_function(CBuf->buffer_hooks->wrap_hook);
	else if (Indented_Text_Mode) indent_line ();

	return(1);
     }

   do_blink = ((((CBuf->syntax_table != NULL)
		 && ((CBuf->syntax_table->char_syntax[(unsigned char) ch] & CLOSE_DELIM_SYNTAX)))
		|| ((ch == ')') || (ch == '}') || (ch == ']')))
	       && !input_pending(&Number_Zero));
   if (did_abbrev == 0)
     (void) jed_insert_byte (ch);
   if (do_blink) blink_match ();
   return 1;
}
Пример #8
0
/*
 * backlog_split()
 *
 * dzieli linie tekstu w buforze na linie ekranowe.
 *
 *  - w - okno do podzielenia
 *
 * XXX function uses n->x0, y0, width, height !!! call calc_window_dimension(). !!!
 */
static int backlog_split(window_t *w, backlog_line_t *b, gboolean show, int y) {
	ncurses_window_t *n = w->priv_data;
	int rows_count = 0;
	/* timestamp */
	int ts_width		= 0;
	gchar *ts_str		= NULL;
	fstr_attr_t *ts_attr	= NULL;
	/* prompt */
	int prompt_width	= b->line->prompt_empty ? 0 : xmbswidth(b->line->str, b->line->prompt_len);
	/* text */
	char *str		= b->line->str  + b->line->prompt_len;
	fstr_attr_t *attr	= b->line->attr + b->line->prompt_len;

	/* set timestamp */
	if (b->line->ts && formated_config_timestamp && config_timestamp_show &&
	    (!w->floating || w->id == WINDOW_LASTLOG_ID))
	{
		fstring_t *s = fstring_new(timestamp_time(formated_config_timestamp, b->line->ts));
		ts_str	 = s->str;
		ts_attr	 = s->attr;
		xfree(s);
		ts_width = xmbswidth(ts_str, xstrlen(ts_str));
	}

	while (*str || rows_count==0) {
		int len, last_space = 0;
		int width = n->width - prompt_width;

		if ((rows_count==0) || !(config_display_indent==1 && prompt_width==0))
			width -= ts_width;

		len = wrap_line(w, width, str, attr, &last_space);

		if (show && (0 <= y && y < n->height)) {
			wmove(n->window, n->y0 + y, n->x0);

			if (ts_width && ((config_display_indent==0) || (rows_count==0))) {
				ncurses_fstring_print_fast(n->window, ts_str, ts_attr, -1);
			} else if (config_display_indent==2 || prompt_width)
				wmove(n->window, n->y0 + y, n->x0 + ts_width);

			if (prompt_width)	/* print prompt */
				ncurses_fstring_print_fast(n->window, b->line->str, b->line->attr, b->line->prompt_len);

			if (width > 0)		/* print text */
				ncurses_fstring_print_fast(n->window, str, attr, len);
		}

		rows_count++;

		if (w->nowrap)
			break;

		str	+= len + last_space;
		attr	+= len + last_space;
		y++;
	}

	if (show && (n->marker == b) && (0 <= y && y < n->height))
		draw_thin_red_line(w, n->y0 + y);

	xfree(ts_str);
	xfree(ts_attr);

	return rows_count;
}