added __cplusplus extern "C".
[swftools.git] / lib / q.h
1 /* q.h
2    Header file for q.c.
3
4    Part of the swftools package.
5    
6    Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
7
8    This file is distributed under the GPL, see file COPYING for details */
9
10 #ifndef __q_h__
11 #define __q_h__
12
13 #include <stdio.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /* dynamically growing mem section */
20 typedef struct _mem_t {
21     char*buffer;
22     int len;
23     int pos;
24 } mem_t;
25
26 typedef struct _ringbuffer_t
27 {
28     void*internal;
29     int available;
30 } ringbuffer_t;
31
32 /* non-nul terminated string */
33 typedef struct _string_t {
34     char*str;
35     int len;
36 } string_t;
37
38 /* key/value pairs of strings */
39 typedef struct _map_t {
40     void*internal;
41 } map_t;
42
43 /* (void*)s referenced by strings */
44 typedef struct _dictionary_t {
45     void*internal;
46 } dictionary_t;
47
48 /* array of strings */
49 typedef struct _stringarray_t
50 {
51     void*internal;
52 } stringarray_t;
53
54 void mem_init(mem_t*mem);
55 int mem_put(mem_t*m, void*data, int length);
56 int mem_putstring(mem_t*m, string_t str);
57 void mem_clear(mem_t*mem);
58 void mem_destroy(mem_t*mem);
59
60 void ringbuffer_init(ringbuffer_t*r);
61 void ringbuffer_put(ringbuffer_t*r, void*buf, int size);
62 int ringbuffer_read(ringbuffer_t*r, void*buf, int size);
63 void ringbuffer_clear(ringbuffer_t*r);
64
65 void string_set(string_t*str, char*text);
66 void string_set2(string_t*str, char*text, int len);
67 void string_dup(string_t*str, const char*text);
68 void string_dup2(string_t*str, const char*text, int len);
69 int string_equals(string_t*str, const char*text);
70
71 void stringarray_init(stringarray_t*sa);
72 void stringarray_put(stringarray_t*sa, string_t str);
73 char* stringarray_at(stringarray_t*sa, int pos);
74 string_t stringarray_at2(stringarray_t*sa, int pos);
75 int stringarray_find(stringarray_t*sa, string_t*str);
76 void stringarray_clear(stringarray_t*sa);
77 void stringarray_destroy(stringarray_t*sa);
78
79 void map_init(map_t*map);
80 void map_put(map_t*map, string_t t1, string_t t2);
81 char* map_lookup(map_t*map, const char*name);
82 void map_dump(map_t*map, FILE*fi, const char*prefix);
83 void map_clear(map_t*map);
84 void map_destroy(map_t*map);
85
86 void dictionary_init(dictionary_t*dict);
87 void dictionary_put(dictionary_t*dict, string_t t1, void* t2);
88 void dictionary_put2(dictionary_t*dict, const char* t1, void* t2);
89 void* dictionary_lookup(dictionary_t*dict, const char*name);
90 void dictionary_dump(dictionary_t*dict, FILE*fi, const char*prefix);
91 void dictionary_del(dictionary_t*dict, const char* name);
92 void dictionary_clear(dictionary_t*dict);
93 void dictionary_destroy(dictionary_t*dict);
94
95 char* strndup(const char*str, int size);
96
97 void* qmalloc_internal(int len);
98 void* qrealloc_internal(void*old, int len);
99 void qfree_internal(void*old);
100
101 #define qmalloc(len) qmalloc_internal(len)
102 #define qrealloc(old, len) qmalloc_internal(old, len)
103 #define qfree(old) qmalloc_internal(old)
104
105 #ifdef __cplusplus
106 }
107 #endif
108
109 #endif //__q_h__