applied patches from Huub Schaeks
[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,2002,2003,2004 Matthias Kramm <kramm@quiss.org>
7  
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
22 #ifndef __q_h__
23 #define __q_h__
24
25 #include <stdio.h>
26 #include "../config.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* dynamically growing mem section */
33 typedef struct _mem_t {
34     char*buffer;
35     int len;
36     int pos;
37 } mem_t;
38
39 /* fifo buffered growing mem region */
40 typedef struct _ringbuffer_t
41 {
42     void*internal;
43     int available;
44 } ringbuffer_t;
45
46 /* non-nul terminated string */
47 typedef struct _string_t {
48     char*str;
49     int len;
50 } string_t;
51
52 /* key/value pairs of strings */
53 typedef struct _map_t {
54     void*internal;
55 } map_t;
56
57 /* (void*)s referenced by strings */
58 typedef struct _dictionary_t {
59     void*internal;
60 } dictionary_t;
61
62 /* array of strings */
63 typedef struct _stringarray_t
64 {
65     void*internal;
66 } stringarray_t;
67
68 /* heap */
69 typedef struct _heap
70 {
71     void**elements;
72     char*data;
73     int elem_size;
74     int size;
75     int max_size;
76     int(*compare)(const void *, const void *);
77 } heap_t;
78
79 void mem_init(mem_t*mem);
80 int mem_put(mem_t*m, void*data, int length);
81 int mem_putstring(mem_t*m, string_t str);
82 void mem_clear(mem_t*mem);
83 void mem_destroy(mem_t*mem);
84
85 void ringbuffer_init(ringbuffer_t*r);
86 void ringbuffer_put(ringbuffer_t*r, void*buf, int size);
87 int ringbuffer_read(ringbuffer_t*r, void*buf, int size);
88 void ringbuffer_clear(ringbuffer_t*r);
89
90 void string_set(string_t*str, char*text);
91 void string_set2(string_t*str, char*text, int len);
92 void string_dup(string_t*str, const char*text);
93 void string_dup2(string_t*str, const char*text, int len);
94 int string_equals(string_t*str, const char*text);
95
96 void stringarray_init(stringarray_t*sa);
97 void stringarray_put(stringarray_t*sa, string_t str);
98 char* stringarray_at(stringarray_t*sa, int pos);
99 string_t stringarray_at2(stringarray_t*sa, int pos);
100 int stringarray_find(stringarray_t*sa, string_t*str);
101 void stringarray_clear(stringarray_t*sa);
102 void stringarray_destroy(stringarray_t*sa);
103
104 void map_init(map_t*map);
105 void map_put(map_t*map, string_t t1, string_t t2);
106 char* map_lookup(map_t*map, const char*name);
107 void map_dump(map_t*map, FILE*fi, const char*prefix);
108 void map_clear(map_t*map);
109 void map_destroy(map_t*map);
110
111 void dictionary_init(dictionary_t*dict);
112 void dictionary_put(dictionary_t*dict, string_t t1, void* t2);
113 void dictionary_put2(dictionary_t*dict, const char* t1, void* t2);
114 stringarray_t* dictionary_index(dictionary_t*dict);
115 void* dictionary_lookup(dictionary_t*dict, const char*name);
116 void dictionary_dump(dictionary_t*dict, FILE*fi, const char*prefix);
117 void dictionary_del(dictionary_t*dict, const char* name);
118 void dictionary_clear(dictionary_t*dict);
119 void dictionary_destroy(dictionary_t*dict);
120 void dictionary_free_all(dictionary_t* dict, void (*freeFunction)(void*));
121
122 void heap_init(heap_t*h,int n,int elem_size, int(*compare)(const void *, const void *));
123 void heap_clear(heap_t*h);
124 void heap_put(heap_t*h, void*e);
125 int heap_size(heap_t*h);
126 void* heap_max(heap_t*h);
127 void* heap_chopmax(heap_t*h);
128 void heap_dump(heap_t*h, FILE*fi);
129 void** heap_flatten(heap_t*h);
130
131 char* strdup_n(const char*str, int size);
132
133 #ifdef __cplusplus
134 }
135 #endif
136
137 #endif //__q_h__