moved from ../src
[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 /* dynamically growing mem section */
16 typedef struct _mem_t {
17     char*buffer;
18     int len;
19     int pos;
20 } mem_t;
21
22 typedef struct _ringbuffer_t
23 {
24     void*internal;
25     int available;
26 } ringbuffer_t;
27
28 /* non-nul terminated string */
29 typedef struct _string_t {
30     char*str;
31     int len;
32 } string_t;
33
34 /* key/value pairs of strings */
35 typedef struct _map_t {
36     void*internal;
37 } map_t;
38
39 /* (void*)s referenced by strings */
40 typedef struct _dictionary_t {
41     void*internal;
42 } dictionary_t;
43
44 /* array of strings */
45 typedef struct _stringarray_t
46 {
47     void*internal;
48 } stringarray_t;
49
50 void mem_init(mem_t*mem);
51 int mem_put(mem_t*m, void*data, int length);
52 int mem_putstring(mem_t*m, string_t str);
53 void mem_clear(mem_t*mem);
54 void mem_destroy(mem_t*mem);
55
56 void ringbuffer_init(ringbuffer_t*r);
57 void ringbuffer_put(ringbuffer_t*r, void*buf, int size);
58 int ringbuffer_read(ringbuffer_t*r, void*buf, int size);
59 void ringbuffer_clear(ringbuffer_t*r);
60
61 void string_set(string_t*str, char*text);
62 void string_set2(string_t*str, char*text, int len);
63 void string_dup(string_t*str, const char*text);
64 void string_dup2(string_t*str, const char*text, int len);
65 int string_equals(string_t*str, const char*text);
66
67 void stringarray_init(stringarray_t*sa);
68 void stringarray_put(stringarray_t*sa, string_t str);
69 char* stringarray_at(stringarray_t*sa, int pos);
70 string_t stringarray_at2(stringarray_t*sa, int pos);
71 int stringarray_find(stringarray_t*sa, string_t*str);
72 void stringarray_clear(stringarray_t*sa);
73 void stringarray_destroy(stringarray_t*sa);
74
75 void map_init(map_t*map);
76 void map_put(map_t*map, string_t t1, string_t t2);
77 char* map_lookup(map_t*map, const char*name);
78 void map_dump(map_t*map, FILE*fi, const char*prefix);
79 void map_clear(map_t*map);
80 void map_destroy(map_t*map);
81
82 void dictionary_init(dictionary_t*dict);
83 void dictionary_put(dictionary_t*dict, string_t t1, void* t2);
84 void dictionary_put2(dictionary_t*dict, const char* t1, void* t2);
85 void* dictionary_lookup(dictionary_t*dict, const char*name);
86 void dictionary_dump(dictionary_t*dict, FILE*fi, const char*prefix);
87 void dictionary_del(dictionary_t*dict, const char* name);
88 void dictionary_clear(dictionary_t*dict);
89 void dictionary_destroy(dictionary_t*dict);
90
91 char* strndup(const char*str, int size);
92
93 void* qmalloc_internal(int len);
94 void* qrealloc_internal(void*old, int len);
95 void qfree_internal(void*old);
96
97 #define qmalloc(len) qmalloc_internal(len)
98 #define qrealloc(old, len) qmalloc_internal(old, len)
99 #define qfree(old) qmalloc_internal(old)
100
101 #endif //__q_h__