#include "buf_misc.h" /* int bbuf_line_new(bbuf_line *buf, int size) { bbuf *newbuf=NULL; bbuf_line *bline=NULL; newbuf = bbuf_new(size); if (newbuf == NULL) { return -1; } bline = malloc(sizeof(bbuf_line)); if (bline == NULL) { return -1; } memset(bline, 0, sizeof(bbuf_line)); bline->buf = newbuf; buf = bline; return 0; } int bbuf_line_pattern(bbuf_line *buf, char *patt, int size) { return -1; } int bbuf_line_add(bbuf_line *buf_line, bbuf *new_data) { return -1; } int bbuf_line_get_line(bbuf_line *buf_line, bbuf *line) { return -1; } int bbuf_line_free(bbuf_line *buf) { return -1; } */ BufLine::BufLine(int size) { buf = new Buf(size); sep=0x0; memset(pattern,0,BUF_PATTER_SIZE); } BufLine::~BufLine() { delete buf; } int BufLine::setpattern(char *pattern) { return -1; } int BufLine::setseperator(char s) { this->sep = s; return 0; } int BufLine::add(char *string, int size) { return -1; } int BufLine::add(Buf *newdata) { buf->concat(newdata); return 0; } int BufLine::pop_line(char **val, int *size) { int idx; if (1 == buf->findc('\n',&idx)) { buf->popsubstring(idx,val,size); buf->shiftleft(1);//remove seperator character return 0; } return -1; } int BufLine::print() { buf->print(); return -1; } /* RETURN_IF_PATTERN_FOUND(*detect_pattern)(char *INPUT_BUFFER, int INPUT_SIZE) */ int BufLine::pop_pattern(int (*detect_pattern)(char *, int, int*), char **val, int *size) { int detected=0; char *buf; int buf_size = 0; int data_size = 0; this->buf->get_ptr(&buf, &buf_size); if ((detected = detect_pattern(buf, buf_size, &data_size)) != 1) { return -1; } this->buf->popsubstring(data_size, val, size); return 0; } /* int bbuf_circ_new(bbuf_circ **circ, int size) { bbuf *buf = NULL; bbuf_circ *cbuf = NULL; buf = bbuf_new(size); if (buf == NULL) { return -1; } cbuf = malloc(sizeof(bbuf_circ)); if (cbuf == NULL) { return -1; } cbuf->buf = buf; cbuf->head = 0; cbuf->tail = 0; *circ = cbuf; return 0; } int bbuf_circ_add(bbuf_circ *circ, bbuf *new_data) { int i=0; int cnt=0; if (circ == NULL) { return -1; } if (new_data == NULL) { return -1; } if (bbuf_size(new_data) <= 0) { return -1; } for (i=0;ibuf[i])) { cnt++; } } return cnt; } int bbuf_circ_get_line(bbuf_circ *circ, bbuf *line) { } int bbuf_circ_reset(bbuf_circ *circ) { if (circ == NULL) { return -1; } circ->head = 0; circ->tail = 0; return 0; } int bbuf_circ_get(bbuf_circ *circ, char *data) { if (circ == NULL) { return -1; } if (data == NULL) { return -1; } if (0 == bbuf_circ_empty(circ)) { *data = circ->buf->buf[circ->tail]; circ->tail = (circ->tail+1)%bbuf_size(circ->buf); return 0; } return -1; } int bbuf_circ_put(bbuf_circ *circ, char data) { if (NULL == circ) { return -1; } circ->buf->buf[circ->head] = data; circ->head = (circ->head+1)%bbuf_size(circ->buf); if (circ->head == circ->tail) { circ->tail = (circ->tail+1)%bbuf_size(circ->buf); } return 0; } int bbuf_circ_empty(bbuf_circ *circ) { if (circ == NULL) { return -1; } return (circ->tail == circ->head); } int bbuf_circ_full(bbuf_circ *circ) { //one lost byte return ((circ->head+1)%bbuf_size(circ->buf) == (circ->tail)); } int bbuf_circ_free(bbuf_circ *circ) { bbuf_free(circ->buf); circ->buf = NULL; free(circ); circ = NULL; } */