1 | /* |
---|
2 | $Id: util.h 261 2006-05-29 21:27:31Z titer $ |
---|
3 | |
---|
4 | Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved. |
---|
5 | |
---|
6 | Redistribution and use in source and binary forms, with or without |
---|
7 | modification, are permitted provided that the following conditions |
---|
8 | are met: |
---|
9 | |
---|
10 | 1. Redistributions of source code must retain the above copyright |
---|
11 | notice, this list of conditions and the following disclaimer. |
---|
12 | 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | notice, this list of conditions and the following disclaimer in the |
---|
14 | documentation and/or other materials provided with the distribution. |
---|
15 | |
---|
16 | THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS "AS IS" AND |
---|
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef TG_UTIL_H |
---|
30 | #define TG_UTIL_H |
---|
31 | |
---|
32 | #include <sys/types.h> |
---|
33 | #include <stdarg.h> |
---|
34 | |
---|
35 | /* macro to shut up "unused parameter" warnings */ |
---|
36 | #ifdef __GNUC__ |
---|
37 | #define SHUTUP __attribute__((unused)) |
---|
38 | #else |
---|
39 | #define SHUTUP |
---|
40 | #endif |
---|
41 | |
---|
42 | typedef void (*add_torrents_func_t)(void*,void*,GList*,const char*,gboolean*); |
---|
43 | |
---|
44 | /* return number of items in array */ |
---|
45 | #define ALEN(a) (sizeof(a) / sizeof((a)[0])) |
---|
46 | |
---|
47 | /* used for a callback function with a data parameter */ |
---|
48 | typedef void (*callbackfunc_t)(void*); |
---|
49 | |
---|
50 | /* try to interpret a string as a textual representation of a boolean */ |
---|
51 | /* note that this isn't localized */ |
---|
52 | gboolean |
---|
53 | strbool(const char *str); |
---|
54 | |
---|
55 | /* return a human-readable string for the size given in bytes. |
---|
56 | the string must be g_free()d */ |
---|
57 | char * |
---|
58 | readablesize(guint64 size); |
---|
59 | |
---|
60 | /* returns a string representing the download ratio. |
---|
61 | the string must be g_free()d */ |
---|
62 | char * |
---|
63 | ratiostr(guint64 down, guint64 up); |
---|
64 | |
---|
65 | /* create a directory and any missing parent directories */ |
---|
66 | gboolean |
---|
67 | mkdir_p(const char *name, mode_t mode); |
---|
68 | |
---|
69 | /* joins a GList of strings into one string using an optional separator */ |
---|
70 | char * |
---|
71 | joinstrlist(GList *list, char *sep); |
---|
72 | |
---|
73 | /* free a GList of strings */ |
---|
74 | void |
---|
75 | freestrlist(GList *list); |
---|
76 | |
---|
77 | /* decodes a string that has been urlencoded */ |
---|
78 | char * |
---|
79 | urldecode(const char *str, int len); |
---|
80 | |
---|
81 | /* return a list of cleaned-up paths, with invalid directories removed */ |
---|
82 | GList * |
---|
83 | checkfilenames(int argc, char **argv); |
---|
84 | |
---|
85 | #ifdef GTK_MAJOR_VERSION |
---|
86 | |
---|
87 | /* if wind is NULL then you must call gtk_widget_show on the returned widget */ |
---|
88 | |
---|
89 | GtkWidget * |
---|
90 | errmsg(GtkWindow *wind, const char *format, ...) |
---|
91 | #ifdef __GNUC__ |
---|
92 | __attribute__ ((format (printf, 2, 3))) |
---|
93 | #endif |
---|
94 | ; |
---|
95 | |
---|
96 | GtkWidget * |
---|
97 | errmsg_full(GtkWindow *wind, callbackfunc_t func, void *data, |
---|
98 | const char *format, ...) |
---|
99 | #ifdef __GNUC__ |
---|
100 | __attribute__ ((format (printf, 4, 5))) |
---|
101 | #endif |
---|
102 | ; |
---|
103 | |
---|
104 | GtkWidget * |
---|
105 | verrmsg(GtkWindow *wind, callbackfunc_t func, void *data, |
---|
106 | const char *format, va_list ap); |
---|
107 | |
---|
108 | #endif /* GTK_MAJOR_VERSION */ |
---|
109 | |
---|
110 | #endif /* TG_UTIL_H */ |
---|