Mercurial > pidgin.yaz
annotate src/util.h @ 6330:def96a62cd0d
[gaim-migrate @ 6829]
Updated the Add Group dialog.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 29 Jul 2003 06:27:13 +0000 |
parents | 158196b2db19 |
children | 2fed50891afa |
rev | line source |
---|---|
4890 | 1 /** |
2 * @file util.h Utility Functions | |
5034
4691c5936c01
[gaim-migrate @ 5377]
Christian Hammond <chipx86@chipx86.com>
parents:
4890
diff
changeset
|
3 * @ingroup core |
4890 | 4 * |
5 * gaim | |
6 * | |
7 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 * | |
23 * @todo Rename the functions so that they live somewhere in the gaim | |
24 * namespace. | |
25 */ | |
26 #ifndef _GAIM_UTIL_H_ | |
27 #define _GAIM_UTIL_H_ | |
28 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
29 #include "account.h" |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
30 |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
31 #ifdef __cplusplus |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
32 extern "C" { |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
33 #endif |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
34 |
4890 | 35 /** |
36 * Normalizes a string, so that it is suitable for comparison. | |
37 * | |
38 * The returned string will point to a static buffer, so if the | |
39 * string is intended to be kept long-term, you <i>must</i> | |
40 * g_strdup() it. Also, calling normalize() twice in the same line | |
41 * will lead to problems. | |
42 * | |
43 * @param str The string to normalize. | |
44 * | |
45 * @return A pointer to the normalized version stored in a static buffer. | |
46 */ | |
47 char *normalize(const char *str); | |
48 | |
49 /** | |
50 * Converts a string to its base-64 equivalent. | |
51 * | |
5426 | 52 * @param buf The data to convert. |
5532 | 53 * @param len The length of the data. |
4890 | 54 * |
55 * @return The base-64 version of @a str. | |
56 * | |
57 * @see frombase64() | |
58 */ | |
5426 | 59 char *tobase64(const unsigned char *buf, size_t len); |
4890 | 60 |
61 /** | |
62 * Converts a string back from its base-64 equivalent. | |
63 * | |
64 * @param str The string to convert back. | |
65 * @param ret_str The returned, non-base-64 string. | |
66 * @param ret_len The returned string length. | |
67 * | |
68 * @see tobase64() | |
69 */ | |
70 void frombase64(const char *str, char **ret_str, int *ret_len); | |
71 | |
72 /** | |
73 * Converts a string to its base-16 equivalent. | |
74 * | |
75 * @param str The string to convert. | |
76 * @param len The length of the string. | |
77 * | |
78 * @return The base-16 string. | |
79 * | |
80 * @see frombase16() | |
81 */ | |
5451 | 82 unsigned char *tobase16(const unsigned char *str, int len); |
4890 | 83 |
84 /** | |
85 * Converts a string back from its base-16 equivalent. | |
86 * | |
87 * @param str The string to convert back. | |
88 * @param ret_str The returned, non-base-16 string. | |
5451 | 89 * |
4890 | 90 * @return The length of the returned string. |
91 * | |
92 * @see tobase16() | |
93 */ | |
5497 | 94 int frombase16(const char *str, unsigned char **ret_str); |
4890 | 95 |
96 /** | |
97 * Waits for all child processes to terminate. | |
98 */ | |
99 void clean_pid(void); | |
100 | |
101 /** | |
102 * Returns the current local time in hour:minute:second form. | |
103 * | |
104 * The returned string is stored in a static buffer, so the result | |
105 * should be g_strdup()'d if it's intended to be used for long. | |
106 * | |
107 * @return The current local time. | |
108 * | |
109 * @see full_date() | |
110 */ | |
111 char *date(void); | |
112 | |
113 /** | |
114 * Adds the necessary HTML code to turn URIs into HTML links in a string. | |
115 * | |
5136 | 116 * @param str The string to linkify. |
4890 | 117 * |
5136 | 118 * @return The linkified text. |
4890 | 119 */ |
5136 | 120 char *linkify_text(const char *str); |
4890 | 121 |
122 /** | |
123 * Converts seconds into a human-readable form. | |
124 * | |
125 * @param sec The seconds. | |
126 * | |
127 * @return A human-readable form, containing days, hours, minutes, and | |
128 * seconds. | |
129 */ | |
130 char *sec_to_text(guint sec); | |
131 | |
132 /** | |
133 * Returns the date and time in human-readable form. | |
134 * | |
135 * The returned string is stored in a static buffer, so the result | |
136 * should be g_strdup()'d if it's intended to be used for long. | |
137 * | |
138 * @return The date and time in human-readable form. | |
139 * | |
140 * @see date() | |
141 */ | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
142 char *full_date(void); |
4890 | 143 |
144 /** | |
145 * Looks for %n, %d, or %t in a string, and replaces them with the | |
146 * specified name, date, and time, respectively. | |
147 * | |
148 * The returned string is stored in a static buffer, so the result | |
149 * should be g_strdup()'d if it's intended to be used for long. | |
150 * | |
151 * @param str The string that may contain the special variables. | |
152 * @param name The sender name. | |
153 * | |
154 * @return A new string where the special variables are expanded. | |
155 */ | |
156 char *away_subs(const char *str, const char *name); | |
157 | |
158 /**` | |
159 * Returns the user's home directory. | |
160 * | |
161 * @return The user's home directory. | |
162 * | |
163 * @see gaim_user_dir() | |
164 */ | |
165 const gchar *gaim_home_dir(void); | |
166 | |
167 /** | |
168 * Returns the gaim settings directory in the user's home directory. | |
169 * | |
170 * @return The gaim settings directory. | |
171 * | |
172 * @see gaim_home_dir() | |
173 */ | |
174 char *gaim_user_dir(void); | |
175 | |
176 /** | |
177 * Copies a string and replaces all HTML linebreaks with newline characters. | |
178 * | |
179 * @param dest The destination string. | |
180 * @param src The source string. | |
181 * @param dest_len The destination string length. | |
182 * | |
183 * @see strncpy_withhtml() | |
184 * @see strdup_withhtml() | |
185 */ | |
186 void strncpy_nohtml(gchar *dest, const gchar *src, size_t dest_len); | |
187 | |
188 /** | |
189 * Copies a string and replaces all newline characters with HTML linebreaks. | |
190 * | |
191 * @param dest The destination string. | |
192 * @param src The source string. | |
193 * @param dest_len The destination string length. | |
194 * | |
195 * @see strncpy_nohtml() | |
196 * @see strdup_withhtml() | |
197 */ | |
198 void strncpy_withhtml(gchar *dest, const gchar *src, size_t dest_len); | |
199 | |
200 /** | |
201 * Duplicates a string and replaces all newline characters from the | |
202 * source string with HTML linebreaks. | |
203 * | |
204 * @param src The source string. | |
205 * | |
206 * @return The new string. | |
207 * | |
208 * @see strncpy_nohtml() | |
209 * @see strncpy_withhtml() | |
210 */ | |
211 gchar *strdup_withhtml(const gchar *src); | |
212 | |
213 /** | |
214 * Ensures that all linefeeds have a matching carriage return. | |
215 * | |
216 * @param str The source string. | |
217 * | |
218 * @return The string with carriage returns. | |
219 */ | |
5136 | 220 char *add_cr(const char *); |
4890 | 221 |
222 /** | |
223 * Strips all linefeeds from a string. | |
224 * | |
225 * @param str The string to strip linefeeds from. | |
226 */ | |
227 void strip_linefeed(char *str); | |
228 | |
229 /** | |
230 * Builds a time_t from the supplied information. | |
231 * | |
232 * @param year The year. | |
233 * @param month The month. | |
234 * @param day The day. | |
235 * @param hour The hour. | |
236 * @param min The minute. | |
237 * @param sec The second. | |
238 * | |
239 * @return A time_t. | |
240 */ | |
241 time_t get_time(int year, int month, int day, | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
242 int hour, int min, int sec); |
4890 | 243 |
244 /** | |
245 * Creates a temporary file and returns a file pointer to it. | |
246 * | |
247 * This is like mkstemp(), but returns a file pointer and uses a | |
248 * pre-set template. It uses the semantics of tempnam() for the | |
249 * directory to use and allocates the space for the file path. | |
250 * | |
251 * The caller is responsible for closing the file and removing it when | |
252 * done, as well as freeing the space pointed to by @a path with | |
253 * g_free(). | |
254 * | |
255 * @param path The returned path to the temp file. | |
256 * | |
257 * @return A file pointer to the temporary file, or @c NULL on failure. | |
258 */ | |
259 FILE *gaim_mkstemp(gchar **path); | |
260 | |
261 /** | |
262 * Attempts to convert a string to UTF-8 from an unknown encoding. | |
263 * | |
264 * This function checks the locale and tries sane defaults. | |
265 * | |
266 * @param str The source string. | |
267 * | |
268 * @return The UTF-8 string, or @c NULL if it could not be converted. | |
269 */ | |
270 char *gaim_try_conv_to_utf8(const char *str); | |
271 | |
272 /** | |
273 * Returns the IP address from a socket file descriptor. | |
274 * | |
275 * @param fd The socket file descriptor. | |
276 * | |
277 * @return The IP address, or @c NULL on error. | |
278 */ | |
279 char *gaim_getip_from_fd(int fd); | |
280 | |
281 /** | |
282 * Compares two UTF-8 strings. | |
283 * | |
284 * @param a The first string. | |
285 * @param b The second string. | |
286 * | |
287 * @return -1 if @a is less than @a b. | |
288 * 0 if @a is equal to @a b. | |
289 * 1 if @a is greater than @a b. | |
290 */ | |
291 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b); | |
292 | |
5515 | 293 /** |
294 * Given a string, this replaces one substring with another | |
295 * and returns a newly allocated string. | |
296 * | |
297 * @param string The string from which to replace stuff. | |
298 * @param delimiter The substring you want replaced. | |
299 * @param replacement The substring you want inserted in place | |
300 * of the delimiting substring. | |
301 */ | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
302 gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, |
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
303 const gchar *replacement); |
5515 | 304 |
5826 | 305 /** |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
306 * Returns a string representing a filesize in the appropriate |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
307 * units (MB, KB, GB, etc.) |
5826 | 308 * |
309 * @param size The size | |
310 */ | |
311 char *gaim_get_size_string(size_t size); | |
312 | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
313 #ifdef __cplusplus |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
314 } |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
315 #endif |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
316 |
4890 | 317 #endif /* _GAIM_UTIL_H_ */ |