New file .gitignore.
[mpdm.git] / mpdm.h
blobb24a03f1ea3d6d6d588909013cd737b830e402e2
1 /*
3 MPDM - Minimum Profit Data Manager
4 Copyright (C) 2003/2007 Angel Ortega <angel@triptico.com>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 http://www.triptico.com
24 /* structural flags */
25 #define MPDM_STRING 0x00000001 /* data can be string-compared */
26 #define MPDM_MULTIPLE 0x00000002 /* data is multiple */
27 #define MPDM_FREE 0x00000004 /* free data at destroy */
29 #define MPDM_IVAL 0x00000010 /* integer value cached in .ival */
30 #define MPDM_RVAL 0x00000020 /* real value cached in .rval */
32 /* 'informative' flags */
33 #define MPDM_HASH 0x00010000 /* data is a hash */
34 #define MPDM_FILE 0x00020000 /* data is a FILE * */
35 #define MPDM_EXEC 0x00040000 /* data is 'executable' */
37 /* mpdm values */
38 typedef struct mpdm_val * mpdm_t;
40 /* a value */
41 struct mpdm_val
43 int flags; /* value flags */
44 int ref; /* reference count */
45 int size; /* data size */
46 void * data; /* the real data */
47 int ival; /* cached integer value */
48 double rval; /* cache real value */
49 mpdm_t prev; /* prev in chain */
50 mpdm_t next; /* next in chain */
54 /* the main control structure */
55 struct mpdm_control
57 mpdm_t root; /* the root hash */
58 mpdm_t cur; /* current value (circular list) */
59 mpdm_t del; /* list of deleted values */
61 int count; /* total count of values */
62 int low_threshold; /* minimum number of values to start sweeping */
63 int default_sweep; /* default swept values on mpdm_sweep(0) */
64 int memory_usage; /* approximate total memory used */
65 int hash_buckets; /* default hash buckets */
68 extern struct mpdm_control * mpdm;
70 mpdm_t mpdm_new(int flags, void * data, int size);
71 mpdm_t mpdm_ref(mpdm_t v);
72 mpdm_t mpdm_unref(mpdm_t v);
73 int mpdm_destroy(mpdm_t v);
74 void mpdm_sweep(int count);
76 int mpdm_size(mpdm_t v);
77 mpdm_t mpdm_clone(mpdm_t v);
78 mpdm_t mpdm_root(void);
80 mpdm_t mpdm_exec(mpdm_t c, mpdm_t args);
81 mpdm_t mpdm_exec_1(mpdm_t c, mpdm_t a1);
82 mpdm_t mpdm_exec_2(mpdm_t c, mpdm_t a1, mpdm_t a2);
83 mpdm_t mpdm_exec_3(mpdm_t c, mpdm_t a1, mpdm_t a2, mpdm_t a3);
85 mpdm_t mpdm_new_a(int flags, int size);
86 mpdm_t mpdm_aclone(mpdm_t v);
88 mpdm_t mpdm_expand(mpdm_t a, int offset, int num);
89 mpdm_t mpdm_collapse(mpdm_t a, int offset, int num);
90 mpdm_t mpdm_aset(mpdm_t a, mpdm_t e, int offset);
91 mpdm_t mpdm_aget(mpdm_t a, int offset);
92 mpdm_t mpdm_ins(mpdm_t a, mpdm_t e, int offset);
93 mpdm_t mpdm_adel(mpdm_t a, int offset);
94 mpdm_t mpdm_shift(mpdm_t a);
95 mpdm_t mpdm_push(mpdm_t a, mpdm_t e);
96 mpdm_t mpdm_pop(mpdm_t a);
97 mpdm_t mpdm_queue(mpdm_t a, mpdm_t e, int size);
98 int mpdm_seek(mpdm_t a, mpdm_t k, int step);
99 int mpdm_seek_s(mpdm_t a, wchar_t * k, int step);
100 int mpdm_bseek(mpdm_t a, mpdm_t k, int step, int * pos);
101 int mpdm_bseek_s(mpdm_t a, wchar_t * k, int step, int * pos);
102 mpdm_t mpdm_sort(mpdm_t a, int step);
103 mpdm_t mpdm_sort_cb(mpdm_t a, int step, mpdm_t asort_cb);
105 mpdm_t mpdm_split(mpdm_t s, mpdm_t a);
106 mpdm_t mpdm_join(mpdm_t s, mpdm_t a);
108 void * mpdm_poke(void * dst, int * dsize, void * org, int osize, int esize);
109 wchar_t * mpdm_pokev(wchar_t * dst, int * dsize, mpdm_t v);
110 wchar_t * mpdm_mbstowcs(char * str, int * s, int l);
111 char * mpdm_wcstombs(wchar_t * str, int * s);
112 mpdm_t mpdm_new_wcs(int flags, wchar_t * str, int size, int cpy);
113 mpdm_t mpdm_new_mbstowcs(int flags, char * str, int l);
114 mpdm_t mpdm_new_wcstombs(int flags, wchar_t * str);
115 mpdm_t mpdm_new_i(int ival);
116 mpdm_t mpdm_new_r(double rval);
117 int mpdm_wcwidth(wchar_t c);
118 mpdm_t mpdm_sprintf(mpdm_t fmt, mpdm_t args);
119 mpdm_t mpdm_ulc(mpdm_t s, int u);
120 wchar_t * mpdm_string(mpdm_t v);
121 mpdm_t mpdm_splice(mpdm_t v, mpdm_t i, int offset, int del);
122 mpdm_t mpdm_strcat(mpdm_t s1, mpdm_t s2);
123 int mpdm_cmp(mpdm_t v1, mpdm_t v2);
124 int mpdm_ival(mpdm_t v);
125 double mpdm_rval(mpdm_t v);
127 mpdm_t mpdm_xnew(mpdm_t (* a1)(mpdm_t, mpdm_t), mpdm_t a2);
129 int mpdm_hsize(mpdm_t h);
130 mpdm_t mpdm_hget(mpdm_t h, mpdm_t k);
131 mpdm_t mpdm_hget_s(mpdm_t h, wchar_t * k);
132 int mpdm_exists(mpdm_t h, mpdm_t k);
133 mpdm_t mpdm_hset(mpdm_t h, mpdm_t k, mpdm_t v);
134 mpdm_t mpdm_hset_s(mpdm_t h, wchar_t * k, mpdm_t v);
135 mpdm_t mpdm_hdel(mpdm_t h, mpdm_t k);
136 mpdm_t mpdm_keys(mpdm_t h);
138 mpdm_t mpdm_dumper(mpdm_t v);
139 void mpdm_dump(mpdm_t v);
140 void mpdm_dump_unref(void);
142 #define MPDM_SGET(r, k) mpdm_sget((r), MPDM_LS((k)))
143 #define MPDM_SSET(r, k, v) mpdm_sset((r), MPDM_LS((k)), (v))
145 mpdm_t mpdm_sget(mpdm_t r, mpdm_t k);
146 mpdm_t mpdm_sset(mpdm_t r, mpdm_t k, mpdm_t v);
148 int mpdm_write_wcs(FILE * f, wchar_t * str);
149 mpdm_t mpdm_new_f(FILE * f);
150 mpdm_t mpdm_open(mpdm_t filename, mpdm_t mode);
151 mpdm_t mpdm_close(mpdm_t fd);
152 mpdm_t mpdm_read(mpdm_t fd);
153 int mpdm_write(mpdm_t fd, mpdm_t v);
154 mpdm_t mpdm_getchar(mpdm_t fd);
155 mpdm_t mpdm_putchar(mpdm_t fd, mpdm_t c);
156 int mpdm_fseek(mpdm_t fd, long offset, int whence);
157 long mpdm_ftell(mpdm_t fd);
158 int mpdm_encoding(mpdm_t charset);
159 int mpdm_unlink(mpdm_t filename);
160 mpdm_t mpdm_stat(mpdm_t filename);
161 int mpdm_chmod(mpdm_t filename, mpdm_t perms);
162 int mpdm_chown(mpdm_t filename, mpdm_t uid, mpdm_t gid);
163 mpdm_t mpdm_glob(mpdm_t spec);
165 mpdm_t mpdm_popen(mpdm_t prg, mpdm_t mode);
166 mpdm_t mpdm_pclose(mpdm_t fd);
168 extern int mpdm_regex_offset;
169 extern int mpdm_regex_size;
170 extern int mpdm_sregex_count;
172 mpdm_t mpdm_regex(mpdm_t r, mpdm_t v, int offset);
173 mpdm_t mpdm_sregex(mpdm_t r, mpdm_t v, mpdm_t s, int offset);
175 mpdm_t mpdm_gettext(mpdm_t str);
176 int mpdm_gettext_domain(mpdm_t dom, mpdm_t data);
178 mpdm_t mpdm_home_dir(void);
179 mpdm_t mpdm_app_dir(void);
181 /* value type testing macros */
183 #define MPDM_IS_ARRAY(v) ((v != NULL) && ((v)->flags) & MPDM_MULTIPLE)
184 #define MPDM_IS_HASH(v) ((v != NULL) && ((v)->flags) & MPDM_HASH)
185 #define MPDM_IS_EXEC(v) ((v != NULL) && ((v)->flags) & MPDM_EXEC)
186 #define MPDM_IS_STRING(v) ((v != NULL) && ((v)->flags) & MPDM_STRING)
188 /* value creation utility macros */
190 #define MPDM_A(n) mpdm_new_a(0,n)
191 #define MPDM_H(n) mpdm_new_a(MPDM_HASH|MPDM_IVAL,n)
192 #define MPDM_LS(s) mpdm_new_wcs(0, s, -1, 0)
193 #define MPDM_S(s) mpdm_new_wcs(0, s, -1, 1)
194 #define MPDM_NS(s,n) mpdm_new_wcs(0, s, n, 1)
195 #define MPDM_ENS(s,n) mpdm_new(MPDM_STRING|MPDM_FREE, s, n)
197 #define MPDM_I(i) mpdm_new_i((i))
198 #define MPDM_R(r) mpdm_new_r((r))
199 #define MPDM_P(p) mpdm_new(0,(void *)p, 0, NULL)
200 #define MPDM_MBS(s) mpdm_new_mbstowcs(0, s, -1)
201 #define MPDM_NMBS(s,n) mpdm_new_mbstowcs(0, s, n)
202 #define MPDM_2MBS(s) mpdm_new_wcstombs(0, s)
204 #define MPDM_X(f) mpdm_new(MPDM_EXEC,f,0)
205 #define MPDM_X2(f,b) mpdm_xnew(f,b)
207 #define MPDM_F(f) mpdm_new_f(f)
209 int mpdm_startup(void);
210 void mpdm_shutdown(void);