Changed the way the documents are installed.
[mpdm.git] / mpdm.h
blob2543b755368ac9ca451684c6914ae16b4bc1748f
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 {
42 int flags; /* value flags */
43 int ref; /* reference count */
44 int size; /* data size */
45 void *data; /* the real data */
46 int ival; /* cached integer value */
47 double rval; /* cache real value */
48 mpdm_t prev; /* prev in chain */
49 mpdm_t next; /* next in chain */
53 /* the main control structure */
54 struct mpdm_control {
55 mpdm_t root; /* the root hash */
56 mpdm_t cur; /* current value (circular list) */
57 mpdm_t del; /* list of deleted values */
59 int count; /* total count of values */
60 int low_threshold; /* minimum number of values to start sweeping */
61 int default_sweep; /* default swept values on mpdm_sweep(0) */
62 int memory_usage; /* approximate total memory used */
63 int hash_buckets; /* default hash buckets */
66 extern struct mpdm_control *mpdm;
68 mpdm_t mpdm_new(int flags, void *data, int size);
69 mpdm_t mpdm_ref(mpdm_t v);
70 mpdm_t mpdm_unref(mpdm_t v);
71 int mpdm_destroy(mpdm_t v);
72 void mpdm_sweep(int count);
74 int mpdm_size(mpdm_t v);
75 mpdm_t mpdm_clone(mpdm_t v);
76 mpdm_t mpdm_root(void);
78 mpdm_t mpdm_exec(mpdm_t c, mpdm_t args);
79 mpdm_t mpdm_exec_1(mpdm_t c, mpdm_t a1);
80 mpdm_t mpdm_exec_2(mpdm_t c, mpdm_t a1, mpdm_t a2);
81 mpdm_t mpdm_exec_3(mpdm_t c, mpdm_t a1, mpdm_t a2, mpdm_t a3);
83 mpdm_t mpdm_new_a(int flags, int size);
84 mpdm_t mpdm_aclone(mpdm_t v);
86 mpdm_t mpdm_expand(mpdm_t a, int offset, int num);
87 mpdm_t mpdm_collapse(mpdm_t a, int offset, int num);
88 mpdm_t mpdm_aset(mpdm_t a, mpdm_t e, int offset);
89 mpdm_t mpdm_aget(mpdm_t a, int offset);
90 mpdm_t mpdm_ins(mpdm_t a, mpdm_t e, int offset);
91 mpdm_t mpdm_adel(mpdm_t a, int offset);
92 mpdm_t mpdm_shift(mpdm_t a);
93 mpdm_t mpdm_push(mpdm_t a, mpdm_t e);
94 mpdm_t mpdm_pop(mpdm_t a);
95 mpdm_t mpdm_queue(mpdm_t a, mpdm_t e, int size);
96 int mpdm_seek(mpdm_t a, mpdm_t k, int step);
97 int mpdm_seek_s(mpdm_t a, wchar_t * k, int step);
98 int mpdm_bseek(mpdm_t a, mpdm_t k, int step, int *pos);
99 int mpdm_bseek_s(mpdm_t a, wchar_t * k, int step, int *pos);
100 mpdm_t mpdm_sort(mpdm_t a, int step);
101 mpdm_t mpdm_sort_cb(mpdm_t a, int step, mpdm_t asort_cb);
103 mpdm_t mpdm_split(mpdm_t s, mpdm_t a);
104 mpdm_t mpdm_join(mpdm_t s, mpdm_t a);
106 void *mpdm_poke(void *dst, int *dsize, void *org, int osize, int esize);
107 wchar_t *mpdm_pokev(wchar_t * dst, int *dsize, mpdm_t v);
108 wchar_t *mpdm_mbstowcs(char *str, int *s, int l);
109 char *mpdm_wcstombs(wchar_t * str, int *s);
110 mpdm_t mpdm_new_wcs(int flags, wchar_t * str, int size, int cpy);
111 mpdm_t mpdm_new_mbstowcs(int flags, char *str, int l);
112 mpdm_t mpdm_new_wcstombs(int flags, wchar_t * str);
113 mpdm_t mpdm_new_i(int ival);
114 mpdm_t mpdm_new_r(double rval);
115 int mpdm_wcwidth(wchar_t c);
116 mpdm_t mpdm_sprintf(mpdm_t fmt, mpdm_t args);
117 mpdm_t mpdm_ulc(mpdm_t s, int u);
118 wchar_t *mpdm_string(mpdm_t v);
119 mpdm_t mpdm_splice(mpdm_t v, mpdm_t i, int offset, int del);
120 mpdm_t mpdm_strcat(mpdm_t s1, mpdm_t s2);
121 int mpdm_cmp(mpdm_t v1, mpdm_t v2);
122 int mpdm_ival(mpdm_t v);
123 double mpdm_rval(mpdm_t v);
124 mpdm_t mpdm_set_ival(mpdm_t v, int ival);
125 mpdm_t mpdm_set_rval(mpdm_t v, double rval);
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 FILE * mpdm_get_filehandle(mpdm_t fd);
159 int mpdm_encoding(mpdm_t charset);
160 int mpdm_unlink(mpdm_t filename);
161 mpdm_t mpdm_stat(mpdm_t filename);
162 int mpdm_chmod(mpdm_t filename, mpdm_t perms);
163 int mpdm_chown(mpdm_t filename, mpdm_t uid, mpdm_t gid);
164 mpdm_t mpdm_glob(mpdm_t spec);
166 mpdm_t mpdm_popen(mpdm_t prg, mpdm_t mode);
167 mpdm_t mpdm_pclose(mpdm_t fd);
169 extern int mpdm_regex_offset;
170 extern int mpdm_regex_size;
171 extern int mpdm_sregex_count;
173 mpdm_t mpdm_regex(mpdm_t r, mpdm_t v, int offset);
174 mpdm_t mpdm_sregex(mpdm_t r, mpdm_t v, mpdm_t s, int offset);
176 mpdm_t mpdm_gettext(mpdm_t str);
177 int mpdm_gettext_domain(mpdm_t dom, mpdm_t data);
179 mpdm_t mpdm_home_dir(void);
180 mpdm_t mpdm_app_dir(void);
182 /* value type testing macros */
184 #define MPDM_IS_ARRAY(v) ((v != NULL) && ((v)->flags) & MPDM_MULTIPLE)
185 #define MPDM_IS_HASH(v) ((v != NULL) && ((v)->flags) & MPDM_HASH)
186 #define MPDM_IS_EXEC(v) ((v != NULL) && ((v)->flags) & MPDM_EXEC)
187 #define MPDM_IS_STRING(v) ((v != NULL) && ((v)->flags) & MPDM_STRING)
189 /* value creation utility macros */
191 #define MPDM_A(n) mpdm_new_a(0,n)
192 #define MPDM_H(n) mpdm_new_a(MPDM_HASH|MPDM_IVAL,n)
193 #define MPDM_LS(s) mpdm_new_wcs(0, s, -1, 0)
194 #define MPDM_S(s) mpdm_new_wcs(0, s, -1, 1)
195 #define MPDM_NS(s,n) mpdm_new_wcs(0, s, n, 1)
196 #define MPDM_ENS(s,n) mpdm_new(MPDM_STRING|MPDM_FREE, s, n)
198 #define MPDM_I(i) mpdm_new_i((i))
199 #define MPDM_R(r) mpdm_new_r((r))
200 #define MPDM_P(p) mpdm_new(0,(void *)p, 0, NULL)
201 #define MPDM_MBS(s) mpdm_new_mbstowcs(0, s, -1)
202 #define MPDM_NMBS(s,n) mpdm_new_mbstowcs(0, s, n)
203 #define MPDM_2MBS(s) mpdm_new_wcstombs(0, s)
205 #define MPDM_X(f) mpdm_new(MPDM_EXEC,f,0)
206 #define MPDM_X2(f,b) mpdm_xnew(f,b)
208 #define MPDM_F(f) mpdm_new_f(f)
210 int mpdm_startup(void);
211 void mpdm_shutdown(void);