aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-util.h
blob: 7c0abe9da9ffbb7974c56253caa13e8bfbcdab9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * e-util.h
 * Copyright 2000, 2001, Ximian, Inc.
 *
 * Authors:
 *   Chris Lahey <clahey@ximian.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License, version 2, as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#ifndef _E_UTIL_H_
#define _E_UTIL_H_

#include <sys/types.h>
#include <gtk/gtktypeutils.h>

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#define E_MAKE_TYPE(l,str,t,ci,i,parent) \
GtkType l##_get_type(void)\
{\
    static GtkType type = 0;\
    if (!type){\
        GtkTypeInfo info = {\
            str,\
            sizeof (t),\
            sizeof (t##Class),\
            (GtkClassInitFunc) ci,\
            (GtkObjectInitFunc) i,\
            NULL, /* reserved 1 */\
            NULL, /* reserved 2 */\
            (GtkClassInitFunc) NULL\
        };\
                type = gtk_type_unique (parent, &info);\
    }\
    return type;\
}


#define E_MAKE_X_TYPE(l,str,t,ci,i,parent,poa_init,offset) \
GtkType l##_get_type(void)\
{\
    static GtkType type = 0;\
    if (!type){\
        GtkTypeInfo info = {\
            str,\
            sizeof (t),\
            sizeof (t##Class),\
            (GtkClassInitFunc) ci,\
            (GtkObjectInitFunc) i,\
            NULL, /* reserved 1 */\
            NULL, /* reserved 2 */\
            (GtkClassInitFunc) NULL\
        };\
                type = bonobo_x_type_unique (\
            parent, poa_init, NULL,\
            offset, &info);\
    }\
    return type;\
}

#if 1
#  define E_OBJECT_CLASS_ADD_SIGNALS(oc,sigs,last) \
    gtk_object_class_add_signals (oc, sigs, last)
#  define E_OBJECT_CLASS_TYPE(oc) (oc)->type
#else
#  define E_OBJECT_CLASS_ADD_SIGNALS(oc,sigs,last)
#  define E_OBJECT_CLASS_TYPE(oc) G_TYPE_FROM_CLASS (oc)
#endif


typedef enum {
    E_FOCUS_NONE,
    E_FOCUS_CURRENT,
    E_FOCUS_START,
    E_FOCUS_END
} EFocus;
int       g_str_compare                                                    (const void        *x,
                                        const void        *y);
int       g_int_compare                                                    (const void        *x,
                                        const void        *y);
char     *e_strdup_strip                                                   (const char        *string);
void      e_free_object_list                                               (GList             *list);
void      e_free_object_slist                                              (GSList            *list);
void      e_free_string_list                                               (GList             *list);
void      e_free_string_slist                                              (GSList            *list);
char     *e_read_file                                                      (const char        *filename);
int       e_write_file                                                     (const char        *filename,
                                        const char        *data,
                                        int                flags);
int       e_write_file_mkstemp                                             (char              *filename,
                                        const char        *data);
int       e_mkdir_hier                                                     (const char        *path,
                                        mode_t             mode);

gchar   **e_strsplit                                                       (const gchar      *string,
                                            const gchar      *delimiter,
                                            gint              max_tokens);
gchar    *e_strstrcase                                                     (const gchar       *haystack,
                                        const gchar       *needle);
void      e_filename_make_safe                                             (gchar             *string);
gchar    *e_format_number                                                  (gint               number);
gchar    *e_format_number_float                                            (gfloat             number);
gboolean  e_create_directory                                               (gchar             *directory);


typedef int (*ESortCompareFunc) (const void *first,
                 const void *second,
                 gpointer    closure);
void      e_sort                                                           (void              *base,
                                        size_t             nmemb,
                                        size_t             size,
                                        ESortCompareFunc   compare,
                                        gpointer           closure);
void      e_bsearch                                                        (const void        *key,
                                        const void        *base,
                                        size_t             nmemb,
                                        size_t             size,
                                        ESortCompareFunc   compare,
                                        gpointer           closure,
                                        size_t            *start,
                                        size_t            *end);
size_t    e_strftime_fix_am_pm                                             (char              *s,
                                        size_t             max,
                                        const char        *fmt,
                                        const struct tm   *tm);

size_t    e_strftime                                                       (char              *s,
                                        size_t             max,
                                        const char        *fmt,
                                        const struct tm   *tm);


/* String to/from double conversion functions */
gdouble   e_flexible_strtod                                                (const gchar       *nptr,
                                        gchar            **endptr);
/* 29 bytes should enough for all possible values that
 * g_ascii_dtostr can produce with the %.17g format.
 * Then add 10 for good measure */
#define E_ASCII_DTOSTR_BUF_SIZE (29 + 10)
gchar    *e_ascii_dtostr                                                   (gchar             *buffer,
                                        gint               buf_len,
                                        const gchar       *format,
                                        gdouble            d);

/* Alternating char * and int arguments with a NULL char * to end.
   Less than 0 for the int means copy the whole string. */
gchar    *e_strdup_append_strings                                          (gchar             *first_string,
                                        ...);

/* Marshallers */
void      e_marshal_INT__INT_INT_POINTER                                   (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_INT__INT_POINTER_INT_POINTER                           (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL                        (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL                      (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL                        (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_NONE__INT_INT_POINTER_POINTER_UINT_UINT e_marshal_NONE__INT_INT_POINTER_POINTER_INT_INT
void      e_marshal_NONE__INT_INT_POINTER_POINTER_INT_INT                  (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_NONE__INT_POINTER_INT_POINTER_POINTER_UINT_UINT e_marshal_NONE__INT_POINTER_INT_POINTER_POINTER_INT_INT
void      e_marshal_NONE__INT_POINTER_INT_POINTER_POINTER_INT_INT          (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_NONE__INT_INT_POINTER_UINT e_marshal_NONE__INT_INT_POINTER_INT
void      e_marshal_NONE__INT_INT_POINTER_INT                              (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_NONE__INT_POINTER_INT_POINTER_UINT e_marshal_NONE__INT_POINTER_INT_POINTER_INT
void      e_marshal_NONE__INT_POINTER_INT_POINTER_INT                      (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT e_marshal_BOOL__INT_INT_POINTER_INT_INT_INT
void      e_marshal_BOOL__INT_INT_POINTER_INT_INT_INT                      (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_BOOL__INT_POINTER_INT_POINTER_INT_INT_UINT e_marshal_BOOL__INT_POINTER_INT_POINTER_INT_INT_INT
void      e_marshal_BOOL__INT_POINTER_INT_POINTER_INT_INT_INT              (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_UINT_UINT e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT
void      e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT          (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);

#define e_marshal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_UINT_UINT e_marshal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_INT_INT
void      e_marshal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_INT_INT  (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_NONE__POINTER_POINTER_INT                              (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_NONE__INT_POINTER_INT_POINTER                          (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_NONE__POINTER_POINTER_POINTER_POINTER                  (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_INT__POINTER_POINTER                                   (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_INT__POINTER_POINTER_POINTER                           (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_INT__POINTER_POINTER_POINTER_POINTER                   (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_INT__POINTER_POINTER_POINTER_POINTER_POINTER           (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_NONE__POINTER_POINTER_POINTER_BOOL                     (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_NONE__POINTER_INT_INT_INT                              (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_INT__OBJECT_POINTER                                    (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_NONE__DOUBLE                                           (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);
void      e_marshal_BOOL__STRING                                           (GtkObject         *object,
                                        GtkSignalFunc      func,
                                        gpointer           func_data,
                                        GtkArg            *args);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _E_UTIL_H_ */