Browse Source

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.
master
Olaf Dreesen 20 years ago
parent
commit
d5b756f08f
4 changed files with 43 additions and 0 deletions
  1. +3
    -0
      buffer.h
  2. +15
    -0
      buffer/buffer_get_token.c
  3. +12
    -0
      buffer/buffer_getc.c
  4. +13
    -0
      buffer/buffer_getn.c

+ 3
- 0
buffer.h View File

@ -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);


+ 15
- 0
buffer/buffer_get_token.c View File

@ -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;blen<len;++blen) {
if ((r=buffer_getc(b,*x))<0) return r;
if (r==0) return blen;
if (byte_chr(charset,clen,*x)<clen) return blen;
++x;
}
return blen;
}

+ 12
- 0
buffer/buffer_getc.c View File

@ -0,0 +1,12 @@
#include "byte.h"
#include "buffer.h"
int buffer_getc(buffer* b,char* x) {
if (b->p==b->n) {
register int blen;
if ((blen=buffer_feed(b))<=0) return blen;
}
*x=b->x[b->p];
++b->p;
return 1;
}

+ 13
- 0
buffer/buffer_getn.c View File

@ -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<len;++blen) {
if ((r=buffer_getc(b,x))<0) return r;
if (r==0) return blen;
++x;
}
return blen;
}

Loading…
Cancel
Save