Пример #1
0
int ConsoleData::getLineReverse(char *s, int max_len, int line_count) {
	int buf_ptr = getLineStartReverse(line_count);
	int cur_len = 0;

	if ((s == NULL) || (buf_ptr < 0)) {
		return -1;
	}

	while ((buf_ptr != head_ptr) && (max_len > 1)) {
		if (data[buf_ptr] && data[buf_ptr] != '\n') {
		  *s = data[buf_ptr];
		  s++; max_len--;
		  cur_len++;
		} 

		if (data[buf_ptr] == 0) {
		  /* end of this line */
		  *s = 0;
		  return cur_len;
		} 
		buf_ptr = bufWrap(buf_ptr + 1);
	}

	*s = 0;
	return (cur_len);
}
Пример #2
0
void ConsoleData::gobbleLine(void) {
	int last_char_lf = 0;

	while ( (tail_ptr != head_ptr) && (!last_char_lf)) {
		if (data[tail_ptr] == 0) {
			last_char_lf = 1;
			cur_numlines--;
		}
		tail_ptr = bufWrap(tail_ptr + 1);
	}

}
Пример #3
0
void ConsoleData::addChar(char c) {

	if (c == '\r') { 
		/* don't insert CR */
		return;
	} else if (c == '\n') {
		/* insert newlines as string terminators */
		c = 0;
		cur_numlines++;
	}

	if (spaceInBuf() < 1) {
		this->gobbleLine();
	}
	this->data[this->head_ptr] = c;
	this->head_ptr = bufWrap(this->head_ptr + 1);
	this->data[this->head_ptr] = 0; /* guarantee a string terminator */

}
Пример #4
0
int ConsoleData::getLineStartReverse(int count) {
	int line_start = -1;
	int curpos = head_ptr;
	int skiplast=1;

	while ((curpos != tail_ptr) && (count)) {
		curpos = bufWrap(curpos-1);
		if ((!skiplast) && (data[curpos] == 0)) {
			count--;
			if (count == 0) {
				return line_start;
			} 
		} 

		skiplast = 0;
		line_start = curpos;
	}

	if (count == 1) {
		return line_start;
	} else {
		return -1;
	}
}
Пример #5
0
err_t queueAppend(queue_t *q, const unsigned char *p) {
  return bufAppend(&q->buf, bufWrap((void *)(uintptr_t)p, q->itemSize));
}