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