summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buf.c4
-rw-r--r--buf.h2
-rw-r--r--buf_misc.c24
-rw-r--r--buf_misc.h1
4 files changed, 27 insertions, 4 deletions
diff --git a/buf.c b/buf.c
index d52336b..2963201 100644
--- a/buf.c
+++ b/buf.c
@@ -284,13 +284,13 @@ Buf* Buf::copy()
char *data=NULL;
int data_size=0;
- this->get(&data, &data_size);
+ this->get_ptr(&data, &data_size);
ret->set(data, data_size);
data=NULL;
return ret;
}
-int Buf::get(char **val, int *size)
+int Buf::get_ptr(char **val, int *size)
{
if (!val)
{
diff --git a/buf.h b/buf.h
index 2d92f33..7ecb2d6 100644
--- a/buf.h
+++ b/buf.h
@@ -62,7 +62,7 @@ public:
int set(char *val, int size);
int set(char *val);
Buf* copy();
- int get(char **val, int *size);
+ int get_ptr(char **val, int *size);
int realloc(int size);
int reduce();
int inc(int size);
diff --git a/buf_misc.c b/buf_misc.c
index d3c540e..386be72 100644
--- a/buf_misc.c
+++ b/buf_misc.c
@@ -64,7 +64,7 @@ BufLine::BufLine(int size)
BufLine::~BufLine()
{
-
+ delete buf;
}
int BufLine::setpattern(char *pattern)
@@ -108,6 +108,28 @@ int BufLine::print()
}
/*
+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;
diff --git a/buf_misc.h b/buf_misc.h
index ef86f42..ded41d7 100644
--- a/buf_misc.h
+++ b/buf_misc.h
@@ -36,6 +36,7 @@ public:
int add(Buf *newdata);
int pop_line(char **val, int *size);
int print();
+ int pop_pattern(int (*detect_pattern)(char *, int, int*), char **val, int *size);
};