From 6838f0f0bbbcbb4007a497b451ec6979e91ee472 Mon Sep 17 00:00:00 2001 From: sanjiyan Date: Mon, 5 Feb 2001 21:27:55 +0000 Subject: [PATCH] aded buffer_getc, buffer_getn get n bytes less only if EOF and buffer_get_token for getting n bytes till finding a termination char or EOF/error. --- buffer.h | 3 +++ buffer/buffer_get_token.c | 15 +++++++++++++++ buffer/buffer_getc.c | 12 ++++++++++++ buffer/buffer_getn.c | 13 +++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 buffer/buffer_get_token.c create mode 100644 buffer/buffer_getc.c create mode 100644 buffer/buffer_getn.c diff --git a/buffer.h b/buffer.h index e8de491..7358565 100644 --- a/buffer.h +++ b/buffer.h @@ -32,6 +32,9 @@ extern int buffer_putsflush(buffer* b,const char* x); extern int buffer_get(buffer* b,char* x,unsigned int len); extern int buffer_bget(buffer* b,char* x,unsigned int len); extern int buffer_feed(buffer* b); +extern int buffer_getc(buffer* b,char* x); +extern int buffer_getn(buffer* b,char* x,unsigned int len); +extern int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen); extern char *buffer_peek(buffer* b); extern void buffer_seek(buffer* b,unsigned int len); diff --git a/buffer/buffer_get_token.c b/buffer/buffer_get_token.c new file mode 100644 index 0000000..954679b --- /dev/null +++ b/buffer/buffer_get_token.c @@ -0,0 +1,15 @@ +#include "byte.h" +#include "buffer.h" +#include "scan.h" + +int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen) { + int blen; + + for (blen=0;blenp==b->n) { + register int blen; + if ((blen=buffer_feed(b))<=0) return blen; + } + *x=b->x[b->p]; + ++b->p; + return 1; +} diff --git a/buffer/buffer_getn.c b/buffer/buffer_getn.c new file mode 100644 index 0000000..de8da12 --- /dev/null +++ b/buffer/buffer_getn.c @@ -0,0 +1,13 @@ +#include "byte.h" +#include "buffer.h" + +int buffer_getn(buffer* b,char* x,unsigned int len) { + int blen; + + for(blen=0;blen