00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef VBUF_H
00013 #define VBUF_H
00014 #define SZ_MAX 4096
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <stdarg.h>
00018
00019
00020
00021 #define DELIM '\\'
00022
00023 #define TOK_EMPTY 0
00024 #define TOK_DELIM 1
00025 #define TOK_PARENT 2
00026 #define TOK_CURRENT 3
00027 #define TOK_ELEMENT 4
00028
00029 #define TOK_ERROR 10
00030 #define TOK_BUF_SMALL 11
00031
00032
00033
00034
00035 struct varbuf {
00036 size_t dlen;
00037 size_t blen;
00038 char *buf;
00039 char *b;
00040 };
00041
00042
00043
00044 struct varstr {
00045 size_t dlen;
00046 size_t blen;
00047 char *buf;
00048 char *b;
00049 };
00050
00051
00052 typedef struct varbuf vbuf;
00053 typedef struct varstr vstr;
00054
00055 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = vballoc(y);
00056 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = vsalloc(y);
00057
00058
00059 struct varbuf *vballoc( size_t len );
00060 void vbfree( vbuf *vb );
00061 void vbclear( vbuf *vb );
00062 void vbresize( vbuf *vb, size_t len );
00063 size_t vbavail( vbuf *vb );
00064 void vbdump( vbuf *vb );
00065 void vbgrow( vbuf *vb, size_t len );
00066 void vbset( vbuf *vb, void *data, size_t len );
00067 void vbskipws( vbuf *vb );
00068 void vbappend( vbuf *vb, void *data, size_t length );
00069 void vbskip( vbuf *vb, size_t skip );
00070 void vboverwrite( vbuf *vbdest, vbuf *vbsrc );
00071
00072
00073 vstr *vsalloc( size_t len );
00074 char *vsb( vstr *vs );
00075 size_t vslen( vstr *vs );
00076 void vsfree( vstr *vs );
00077 void vsset( vstr *vs, char *s );
00078 void vsnset( vstr *vs, char *s, size_t n );
00079 void vsgrow( vstr *vs, size_t len );
00080 size_t vsavail( vstr *vs );
00081 void vscat( vstr *vs, char *str );
00082 void vsncat( vstr *vs, char *str, size_t len );
00083 void vsnprepend( vstr *vs, char *str, size_t len ) ;
00084 void vsskip( vstr *vs, size_t len );
00085 int vscmp( vstr *vs, char *str );
00086 void vsskipws( vstr *vs );
00087 void vs_printf( vstr *vs, char *fmt, ... );
00088 void vs_printfa( vstr *vs, char *fmt, ... );
00089 void vshexdump( vstr *vs, char *b, size_t start, size_t stop, int ascii );
00090 int vscatprintf( vstr *vs, char *fmt, ... );
00091 void vsvprintf( vstr *vs, char *fmt, va_list ap );
00092 void vstrunc( vstr *vs, size_t off );
00093 int vslast( vstr *vs );
00094 void vscharcat( vstr *vs, int ch );
00095 int vsutf16( vstr *vs, vbuf *in );
00096
00097 int vs_parse_escaped_string( vstr *vs, char *str, size_t len );
00098
00099
00100
00101
00102
00103
00104
00105 void unicode_init();
00106 void unicode_close();
00107 int utf16_write( FILE* stream, const void *buf, size_t count );
00108 int utf16_fprintf( FILE* stream, const char *fmt, ... );
00109 int utf16to8( char *inbuf_o, char *outbuf_o, int length );
00110 int utf8to16( char *inbuf_o, int iblen, char *outbuf_o, int oblen);
00111 int vb_utf8to16T( vbuf *bout, char *cin, int inlen );
00112 int vb_utf16to8( vbuf *dest, char *buf, int len );
00113 int iso8859_1to8( char *inbuf_o, char *outbuf_o, int length );
00114 int utf8toascii( const char *inbuf_o, char *outbuf_o, int length );
00115
00116
00117 void winhex(FILE* stream, unsigned char *hbuf, int start, int stop, int loff);
00118 void winhex8(FILE *stream, unsigned char *hbuf, int start, int stop, int loff );
00119
00120 void vbwinhex8(vbuf *vb, unsigned char *hbuf, int start, int stop, int loff );
00121
00122
00123 int find_in_buf(char *buf, char *what, int sz, int len, int start);
00124
00125
00126 int get_int( char *array );
00127
00128 int find_nl( vstr *vs );
00129 int skip_nl( char *s );
00130
00131 int vb_skipline( struct varbuf *vb );
00132
00133
00134 int gethexorstr(char **c, char *wb);
00135 char *esc_index( char *s, int c );
00136 char *esc_rindex( char *s, int c );
00137
00138 char *tok_esc_char( char *s, int *is_esc, int *c );
00139 int vb_path_token( vbuf *tok, char **path );
00140
00141 int gettoken( char *tok, int len, char **path, char delim );
00142 #endif