]> git.sur5r.net Git - glabels/blob - src/mygal/e-util.h
Imported Upstream version 2.2.8
[glabels] / src / mygal / e-util.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* 
3  * e-util.h
4  * Copyright 2000, 2001, Ximian, Inc.
5  *
6  * Authors:
7  *   Chris Lahey <clahey@ximian.com>
8  *
9  * Modified for gLabels by:
10  *   Jim Evins <evins@snaught.com>
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public
14  * License, version 2, as published by the Free Software Foundation.
15  *
16  * This library is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26
27 #ifndef _E_UTIL_H_
28 #define _E_UTIL_H_
29
30 #include <sys/types.h>
31 #include <glib-object.h>
32 #include <limits.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #pragma }
37 #endif /* __cplusplus */
38
39 #include "e-marshal.h"
40
41 #define E_MAKE_TYPE(l,str,t,ci,i,parent) \
42 GType l##_get_type(void)\
43 {\
44         static GType type = 0;                          \
45         if (!type){                                     \
46                 static GTypeInfo const object_info = {  \
47                         sizeof (t##Class),              \
48                                                         \
49                         (GBaseInitFunc) NULL,           \
50                         (GBaseFinalizeFunc) NULL,       \
51                                                         \
52                         (GClassInitFunc) ci,            \
53                         (GClassFinalizeFunc) NULL,      \
54                         NULL,   /* class_data */        \
55                                                         \
56                         sizeof (t),                     \
57                         0,      /* n_preallocs */       \
58                         (GInstanceInitFunc) i,          \
59                 };                                      \
60                 type = g_type_register_static (parent, str, &object_info, 0);   \
61         }                                               \
62         return type;                                    \
63 }
64
65
66 #define E_MAKE_X_TYPE(l,str,t,ci,i,parent,poa_init,offset)      \
67 GtkType l##_get_type(void)                                      \
68 {                                                               \
69         static GtkType type = 0;                                \
70         if (!type){                                             \
71                 GTypeInfo info = {                              \
72                         sizeof (t##Class),                      \
73                                                                 \
74                         (GBaseInitFunc) NULL,                   \
75                         (GBaseFinalizeFunc) NULL,               \
76                                                                 \
77                         (GClassInitFunc) ci,                    \
78                         (GClassFinalizeFunc) NULL,              \
79                                                                 \
80                         NULL,   /* class_data */                \
81                                                                 \
82                         sizeof (t),                             \
83                         0,      /* n_preallocs */               \
84                         (GInstanceInitFunc) i,                  \
85                 };                                              \
86                 type = bonobo_x_type_unique (                   \
87                         parent, poa_init, NULL,                 \
88                         offset, &info, str);                    \
89         }                                                       \
90         return type;                                            \
91 }
92
93 #define GET_STRING_ARRAY_FROM_ELLIPSIS(labels, first_string) \
94         { \
95                 va_list args; \
96                 int i; \
97                 char *s; \
98  \
99                 va_start (args, (first_string)); \
100  \
101                 i = 0; \
102                 for (s = (first_string); s; s = va_arg (args, char *)) \
103                         i++; \
104                 va_end (args); \
105  \
106                 (labels) = g_new (char *, i + 1); \
107  \
108                 va_start (args, (first_string)); \
109                 i = 0; \
110                 for (s = (first_string); s; s = va_arg (args, char *)) \
111                         (labels)[i++] = s; \
112  \
113                 va_end (args); \
114                 (labels)[i] = NULL; \
115         }
116
117
118 #define GET_DUPLICATED_STRING_ARRAY_FROM_ELLIPSIS(labels, first_string) \
119         { \
120                 int i; \
121                 GET_STRING_ARRAY_FROM_ELLIPSIS ((labels), (first_string)); \
122                 for (i = 0; labels[i]; i++) \
123                         labels[i] = g_strdup (labels[i]); \
124         }
125
126
127 #if 0
128 #  define E_OBJECT_CLASS_ADD_SIGNALS(oc,sigs,last) \
129         gtk_object_class_add_signals (oc, sigs, last)
130 #  define E_OBJECT_CLASS_TYPE(oc) (oc)->type
131 #else
132 #  define E_OBJECT_CLASS_ADD_SIGNALS(oc,sigs,last)
133 #  define E_OBJECT_CLASS_TYPE(oc) G_TYPE_FROM_CLASS (oc)
134 #endif
135
136
137 typedef enum {
138         E_FOCUS_NONE,
139         E_FOCUS_CURRENT,
140         E_FOCUS_START,
141         E_FOCUS_END
142 } EFocus;
143 int       g_str_compare                                                    (const void        *x,
144                                                                             const void        *y);
145 int       g_collate_compare                                                (const void        *x,
146                                                                             const void        *y);
147 int       g_int_compare                                                    (const void        *x,
148                                                                             const void        *y);
149 char     *e_strdup_strip                                                   (const char        *string);
150 void      e_free_object_list                                               (GList             *list);
151 void      e_free_object_slist                                              (GSList            *list);
152 void      e_free_string_list                                               (GList             *list);
153 void      e_free_string_slist                                              (GSList            *list);
154 char     *e_read_file                                                      (const char        *filename);
155 int       e_write_file                                                     (const char        *filename,
156                                                                             const char        *data,
157                                                                             int                flags);
158 int       e_write_file_mkstemp                                             (char              *filename,
159                                                                             const char        *data);
160 int       e_mkdir_hier                                                     (const char        *path,
161                                                                             mode_t             mode);
162
163 gchar   **e_strsplit                                                       (const gchar      *string,
164                                                                             const gchar      *delimiter,
165                                                                             gint              max_tokens);
166 gchar    *e_strstrcase                                                     (const gchar       *haystack,
167                                                                             const gchar       *needle);
168 /* This only makes a filename safe for usage as a filename.  It still may have shell meta-characters in it. */
169 void      e_filename_make_safe                                             (gchar             *string);
170 gchar    *e_format_number                                                  (gint               number);
171 gchar    *e_format_number_float                                            (gfloat             number);
172 gboolean  e_create_directory                                               (gchar             *directory);
173 gchar   **e_strdupv                                                        (const gchar      **str_array);
174
175
176 typedef int (*ESortCompareFunc) (const void *first,
177                                  const void *second,
178                                  gpointer    closure);
179 void     e_sort                (void             *base,
180                                 size_t            nmemb,
181                                 size_t            size,
182                                 ESortCompareFunc  compare,
183                                 gpointer          closure);
184 void     e_bsearch             (const void       *key,
185                                 const void       *base,
186                                 size_t            nmemb,
187                                 size_t            size,
188                                 ESortCompareFunc  compare,
189                                 gpointer          closure,
190                                 size_t           *start,
191                                 size_t           *end);
192 size_t   e_strftime_fix_am_pm  (char             *s,
193                                 size_t            max,
194                                 const char       *fmt,
195                                 const struct tm  *tm);
196
197 size_t   e_strftime             (char              *s,
198                                  size_t             max,
199                                  const char        *fmt,
200                                  const struct tm   *tm);
201
202 size_t   e_utf8_strftime_fix_am_pm  (char             *s,
203                                      size_t            max,
204                                      const char       *fmt,
205                                      const struct tm  *tm);
206
207 size_t   e_utf8_strftime        (char              *s,
208                                  size_t             max,
209                                  const char        *fmt,
210                                  const struct tm   *tm);
211
212 /* String to/from double conversion functions */
213 gdouble   e_flexible_strtod     (const gchar       *nptr,
214                                  gchar            **endptr);
215
216 /* 29 bytes should enough for all possible values that
217  * g_ascii_dtostr can produce with the %.17g format.
218  * Then add 10 for good measure */
219 #define E_ASCII_DTOSTR_BUF_SIZE (DBL_DIG + 12 + 10)
220 gchar    *e_ascii_dtostr                                                   (gchar             *buffer,
221                                                                             gint               buf_len,
222                                                                             const gchar       *format,
223                                                                             gdouble            d);
224
225 /* Alternating char * and int arguments with a NULL char * to end.
226    Less than 0 for the int means copy the whole string. */
227 gchar    *e_strdup_append_strings                                          (gchar             *first_string,
228                                                                             ...);
229
230 #ifdef __cplusplus
231 }
232 #endif /* __cplusplus */
233
234 #endif /* _E_UTIL_H_ */