comparison src/vbuf.h @ 116:ed2a260bbb98 stable-0-6-25

improve handling of content-type charset values in mime parts
author Carl Byington <carl@five-ten-sg.com>
date Fri, 16 Jan 2009 15:23:52 -0800
parents b12f4e50e2e8
children 6395ced2b8b2
comparison
equal deleted inserted replaced
115:7689c006b166 116:ed2a260bbb98
14 #define SZ_MAX 4096 14 #define SZ_MAX 4096
15 #include <stdlib.h> 15 #include <stdlib.h>
16 #include <stdio.h> 16 #include <stdio.h>
17 #include <stdarg.h> 17 #include <stdarg.h>
18 /***************************************************/ 18 /***************************************************/
19
20 // Tokenizer const TOK_EMPTY, TOK_ELEMENT, DELIM
21 #define DELIM '\\'
22
23 #define TOK_EMPTY 0
24 #define TOK_DELIM 1
25 #define TOK_PARENT 2
26 #define TOK_CURRENT 3
27 #define TOK_ELEMENT 4
28
29 #define TOK_ERROR 10
30 #define TOK_BUF_SMALL 11
31
32 19
33 20
34 // Variable-length buffers 21 // Variable-length buffers
35 struct varbuf { 22 struct varbuf {
36 size_t dlen; //length of data stored in buffer 23 size_t dlen; //length of data stored in buffer
52 typedef struct varbuf vbuf; 39 typedef struct varbuf vbuf;
53 typedef struct varstr vstr; 40 typedef struct varstr vstr;
54 41
55 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = vballoc(y); 42 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = vballoc(y);
56 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = vsalloc(y); 43 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = vsalloc(y);
44
45 int skip_nl( char *s ); // returns the width of the newline at s[0]
46 int find_nl( vstr *vs ); // find newline of type type in b
57 47
58 // vbuf functions 48 // vbuf functions
59 struct varbuf *vballoc( size_t len ); 49 struct varbuf *vballoc( size_t len );
60 void vbfree( vbuf *vb ); 50 void vbfree( vbuf *vb );
61 void vbclear( vbuf *vb ); //ditch the data, keep the buffer 51 void vbclear( vbuf *vb ); //ditch the data, keep the buffer
84 void vsskip( vstr *vs, size_t len ); 74 void vsskip( vstr *vs, size_t len );
85 int vscmp( vstr *vs, char *str ); 75 int vscmp( vstr *vs, char *str );
86 void vsskipws( vstr *vs ); 76 void vsskipws( vstr *vs );
87 void vs_printf( vstr *vs, char *fmt, ... ); 77 void vs_printf( vstr *vs, char *fmt, ... );
88 void vs_printfa( vstr *vs, char *fmt, ... ); 78 void vs_printfa( vstr *vs, char *fmt, ... );
89 void vshexdump( vstr *vs, char *b, size_t start, size_t stop, int ascii ); 79 void vshexdump( vstr *vs, const char *b, size_t start, size_t stop, int ascii );
90 int vscatprintf( vstr *vs, char *fmt, ... ); 80 int vscatprintf( vstr *vs, char *fmt, ... );
91 void vsvprintf( vstr *vs, char *fmt, va_list ap ); 81 void vsvprintf( vstr *vs, char *fmt, va_list ap );
92 void vstrunc( vstr *vs, size_t off ); // Drop chars [off..dlen] 82 void vstrunc( vstr *vs, size_t off ); // Drop chars [off..dlen]
93 int vslast( vstr *vs ); // returns the last character stored in a vstr string 83 int vslast( vstr *vs ); // returns the last character stored in a vstr string
94 void vscharcat( vstr *vs, int ch ); 84 void vscharcat( vstr *vs, int ch );
95 int vsutf16( vstr *vs, vbuf *in ); //in: in=zero-terminated utf16; out: vs=utf8; returns: 0 on success, else on fail
96 85
97 int vs_parse_escaped_string( vstr *vs, char *str, size_t len );
98
99
100 /*
101 * Windows unicode output trash - this stuff sucks
102 * TODO: most of this should not be here
103 */
104 86
105 void unicode_init(); 87 void unicode_init();
106 void unicode_close(); 88 void unicode_close();
107 int utf16_write( FILE* stream, const void *buf, size_t count ); 89 size_t vb_utf16to8(vbuf *dest, const char *inbuf, int iblen);
108 int utf16_fprintf( FILE* stream, const char *fmt, ... ); 90 size_t vb_utf8to8bit(vbuf *dest, const char *inbuf, int iblen, const char* charset);
109 int utf16to8( char *inbuf_o, char *outbuf_o, int length );
110 int utf8to16( char *inbuf_o, int iblen, char *outbuf_o, int oblen);
111 int vb_utf8to16T( vbuf *bout, char *cin, int inlen );
112 int vb_utf16to8( vbuf *dest, char *buf, int len );
113 int iso8859_1to8( char *inbuf_o, char *outbuf_o, int length );
114 int utf8toascii( const char *inbuf_o, char *outbuf_o, int length );
115 91
116 /* dump ascii hex in windoze format */
117 void winhex(FILE* stream, unsigned char *hbuf, int start, int stop, int loff);
118 void winhex8(FILE *stream, unsigned char *hbuf, int start, int stop, int loff );
119
120 void vbwinhex8(vbuf *vb, unsigned char *hbuf, int start, int stop, int loff );
121
122 /* general search routine, find something in something else */
123 int find_in_buf(char *buf, char *what, int sz, int len, int start);
124
125 /* Get INTEGER from memory. This is probably low-endian specific? */
126 int get_int( char *array );
127
128 int find_nl( vstr *vs ); // find newline of type type in b
129 int skip_nl( char *s ); // returns the width of the newline at s[0]
130 //int vb_readline( struct varbuf *vb, int *ctype, FILE *in ); // read *AT LEAST* one full line of data from in
131 int vb_skipline( struct varbuf *vb ); // in: vb->b == "stuff\nmore_stuff"; out: vb->b == "more_stuff" 92 int vb_skipline( struct varbuf *vb ); // in: vb->b == "stuff\nmore_stuff"; out: vb->b == "more_stuff"
132 /* Get a string of HEX bytes (space separated),
133 * or if first char is ' get an ASCII string instead. */
134 int gethexorstr(char **c, char *wb);
135 char *esc_index( char *s, int c ); // just like index(3), but works on strings with escape sequences
136 char *esc_rindex( char *s, int c ); // just like rindex(3), but works on strings with escape sequences
137
138 char *tok_esc_char( char *s, int *is_esc, int *c );
139 int vb_path_token( vbuf *tok, char **path ); // returns things like TOK_EMPTY, TOK_ERROR, complete list at top
140
141 int gettoken( char *tok, int len, char **path, char delim ); // Path tokenizer: increments path, dumps token in tok
142 #endif 93 #endif