示例#1
0
文件: log.c 项目: P4N74/radare2
R_API void r_core_log_del(RCore *core, int n) {
	int idx;
	if (n > 0) {
		if (n + 1 >= core->log->last) {
			core->log->first = core->log->last;
			r_strpool_empty (core->log->sp);
			return;
		}
		if (n < core->log->first) {
			return;
		}
		idx = n - core->log->first;
		if (idx < 0) {
			return;
		}
		core->log->first += idx + 1;
		char *msg = r_strpool_get_i (core->log->sp, idx);
		// if (idx >= core->log->last) {
		if (!msg || !*msg) {
			core->log->first = core->log->last;
			r_strpool_empty (core->log->sp);
		} else {
			r_strpool_slice (core->log->sp, idx);
		}
	} else {
		core->log->first = core->log->last;
		r_strpool_empty (core->log->sp);
	}
}
示例#2
0
static void color_line(const char *line, RStrpool *p, RList *ml){
	int m_len, offset = 0;
	char *m_addr;
	RListIter *it;
	RRegexMatch *m;
	char *inv[2] = {
		R_CONS_INVERT (true, true),
		R_CONS_INVERT (false, true)
	};
	int linv[2] = {
		strlen (inv[0]),
		strlen(inv[1])
	};
	r_strpool_empty (p);
	r_list_foreach (ml, it, m) {
		/* highlight a match */
		r_strpool_memcat (p, line + offset, m->rm_so - offset);
		r_strpool_memcat (p, inv[0], linv[0]);
		m_len = m->rm_eo - m->rm_so;
		if (m_len<0) m_len = 0;
		m_addr = r_str_ndup (line + m->rm_so, m_len);
		if (m_addr) {
			/* in case there's a CSI in the middle of this match*/
			m_len = r_str_ansi_filter (m_addr, NULL, NULL, m_len);
			if (m_len<0) m_len = 0;
			r_strpool_memcat (p, m_addr, m_len);
			r_strpool_memcat (p, inv[1], linv[1]);
			offset = m->rm_eo;
			free(m_addr);
		}

	}
示例#3
0
文件: log.c 项目: Darredevil/radare2
R_API void r_core_log_del(RCore *core, int n) {
	int idx;
	if (n>0) {
		if (n > core->log->last)
			n = core->log->last;
		idx = n-core->log->first;
		if (idx<0) return;
		core->log->first += idx+1;
		/* s= */ r_strpool_get_i (core->log->sp, idx);
		r_strpool_slice (core->log->sp, idx);
	} else {
		core->log->first = core->log->last;
		r_strpool_empty (core->log->sp);
	}
}
示例#4
0
文件: less.c 项目: kcobra/radare2
static void color_line(const char *line, RStrpool *p, RRegexMatch *ms){
	int i, m_len;
	int offset = 0;
	char *m_addr;
	char *inv[2] = {R_CONS_INVERT(R_TRUE, R_TRUE),
			R_CONS_INVERT(R_FALSE, R_TRUE)};
	int linv[2] = {strlen(inv[0]), strlen(inv[1])};

	r_strpool_empty(p);
	for (i = 0; i < NMATCHES; i++) {
		if (ms[i].rm_eo && (i < NMATCHES - 1)) {
			/* highlight a match */
			r_strpool_memcat (p, line + offset,
					  ms[i].rm_so - offset);
			r_strpool_memcat (p, inv[0], linv[0]);

			m_len = ms[i].rm_eo - ms[i].rm_so;
			m_addr = r_str_ndup (line + ms[i].rm_so, m_len);
			if (m_addr) {
				if(r_str_ansi_chrn (m_addr, m_len) - m_addr < m_len ){
					/* there's a CSI in the middle of this match*/
					m_len = r_str_ansi_filter(m_addr,
							NULL, NULL, m_len);
				}
				r_strpool_memcat (p, m_addr, m_len);
				r_strpool_memcat (p, inv[1], linv[1]);
				offset = ms[i].rm_eo;
				free(m_addr);
			}
		} else {
			/* append final part of string w/o matches */
			r_strpool_append(p, line + offset);
			break;
		}
	}
}