Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
2.1 KiB

  1. #ifndef BUFFER_H
  2. #define BUFFER_H
  3. typedef struct buffer {
  4. char *x;
  5. unsigned int p;
  6. unsigned int n;
  7. unsigned int a;
  8. int fd;
  9. int (*op)();
  10. } buffer;
  11. #define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), 0, (fd), (op) }
  12. #define BUFFER_INIT_READ(op,fd,buf,len) { (buf), 0, 0, (len), (fd), (op) }
  13. #define BUFFER_INSIZE 8192
  14. #define BUFFER_OUTSIZE 8192
  15. extern void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned int ylen);
  16. extern int buffer_flush(buffer* b);
  17. extern int buffer_put(buffer* b,const char* x,unsigned int len);
  18. extern int buffer_putalign(buffer* b,const char* x,unsigned int len);
  19. extern int buffer_putflush(buffer* b,const char* x,unsigned int len);
  20. extern int buffer_puts(buffer* b,const char* x);
  21. extern int buffer_putsalign(buffer* b,const char* x);
  22. extern int buffer_putsflush(buffer* b,const char* x);
  23. extern int buffer_putspace(buffer* b);
  24. #define buffer_PUTC(s,c) \
  25. ( ((s)->n != (s)->p) \
  26. ? ( (s)->x[(s)->p++] = (c), 0 ) \
  27. : buffer_put((s),&(c),1) \
  28. )
  29. extern int buffer_get(buffer* b,char* x,unsigned int len);
  30. extern int buffer_bget(buffer* b,char* x,unsigned int len);
  31. extern int buffer_feed(buffer* b);
  32. extern int buffer_getc(buffer* b,char* x);
  33. extern int buffer_getn(buffer* b,char* x,unsigned int len);
  34. extern int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen);
  35. #define buffer_getline(b,x,len) buffer_get_token((b),(x),(len),"\n",1)
  36. extern char *buffer_peek(buffer* b);
  37. extern void buffer_seek(buffer* b,unsigned int len);
  38. #define buffer_PEEK(s) ( (s)->x + (s)->n )
  39. #define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) )
  40. #define buffer_GETC(s,c) \
  41. ( ((s)->p > 0) \
  42. ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \
  43. : buffer_get((s),(c),1) \
  44. )
  45. extern int buffer_copy(buffer* out,buffer* in);
  46. extern int buffer_putulong(buffer *b,unsigned long l);
  47. extern int buffer_put8long(buffer *b,unsigned long l);
  48. extern int buffer_putxlong(buffer *b,unsigned long l);
  49. extern int buffer_putlong(buffer *b,unsigned long l);
  50. extern buffer *buffer_0;
  51. extern buffer *buffer_0small;
  52. extern buffer *buffer_1;
  53. extern buffer *buffer_1small;
  54. extern buffer *buffer_2;
  55. #endif