Mercurial > pidgin.yaz
annotate src/util.h @ 5218:4ee151ad8233
[gaim-migrate @ 5588]
What can I say. I'm tired.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 26 Apr 2003 08:33:49 +0000 |
parents | 381da05cb5ed |
children | 8d8bf0d31a23 |
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 | |
29 /** | |
30 * Normalizes a string, so that it is suitable for comparison. | |
31 * | |
32 * The returned string will point to a static buffer, so if the | |
33 * string is intended to be kept long-term, you <i>must</i> | |
34 * g_strdup() it. Also, calling normalize() twice in the same line | |
35 * will lead to problems. | |
36 * | |
37 * @param str The string to normalize. | |
38 * | |
39 * @return A pointer to the normalized version stored in a static buffer. | |
40 */ | |
41 char *normalize(const char *str); | |
42 | |
43 /** | |
44 * Converts a string to its base-64 equivalent. | |
45 * | |
46 * @param str The string to convert. | |
47 * | |
48 * @return The base-64 version of @a str. | |
49 * | |
50 * @see frombase64() | |
51 */ | |
52 char *tobase64(const char *str); | |
53 | |
54 /** | |
55 * Converts a string back from its base-64 equivalent. | |
56 * | |
57 * @param str The string to convert back. | |
58 * @param ret_str The returned, non-base-64 string. | |
59 * @param ret_len The returned string length. | |
60 * | |
61 * @see tobase64() | |
62 */ | |
63 void frombase64(const char *str, char **ret_str, int *ret_len); | |
64 | |
65 /** | |
66 * Converts a string to its base-16 equivalent. | |
67 * | |
68 * @param str The string to convert. | |
69 * @param len The length of the string. | |
70 * | |
71 * @return The base-16 string. | |
72 * | |
73 * @see frombase16() | |
74 */ | |
75 char *tobase16(const char *str, int len); | |
76 | |
77 /** | |
78 * Converts a string back from its base-16 equivalent. | |
79 * | |
80 * @param str The string to convert back. | |
81 * @param ret_str The returned, non-base-16 string. | |
82 * | |
83 * @return The length of the returned string. | |
84 * | |
85 * @see tobase16() | |
86 */ | |
87 int frombase16(const char *str, char **ret_str); | |
88 | |
89 /** | |
90 * Waits for all child processes to terminate. | |
91 */ | |
92 void clean_pid(void); | |
93 | |
94 /** | |
95 * Returns the current local time in hour:minute:second form. | |
96 * | |
97 * The returned string is stored in a static buffer, so the result | |
98 * should be g_strdup()'d if it's intended to be used for long. | |
99 * | |
100 * @return The current local time. | |
101 * | |
102 * @see full_date() | |
103 */ | |
104 char *date(void); | |
105 | |
106 /** | |
107 * Adds the necessary HTML code to turn URIs into HTML links in a string. | |
108 * | |
5136 | 109 * @param str The string to linkify. |
4890 | 110 * |
5136 | 111 * @return The linkified text. |
4890 | 112 */ |
5136 | 113 char *linkify_text(const char *str); |
4890 | 114 |
115 /** | |
116 * Converts seconds into a human-readable form. | |
117 * | |
118 * @param sec The seconds. | |
119 * | |
120 * @return A human-readable form, containing days, hours, minutes, and | |
121 * seconds. | |
122 */ | |
123 char *sec_to_text(guint sec); | |
124 | |
125 /** | |
126 * Finds a gaim_account with the specified name and protocol ID. | |
127 * | |
128 * @param name The name of the account. | |
129 * @param protocol The protocol type. | |
130 * | |
131 * @return The gaim_account, if found, or @c NULL otherwise. | |
132 */ | |
133 struct gaim_account *gaim_account_find(const char *name, | |
134 int protocol) G_GNUC_PURE; | |
135 | |
136 /** | |
137 * Returns the date and time in human-readable form. | |
138 * | |
139 * The returned string is stored in a static buffer, so the result | |
140 * should be g_strdup()'d if it's intended to be used for long. | |
141 * | |
142 * @return The date and time in human-readable form. | |
143 * | |
144 * @see date() | |
145 */ | |
146 char *full_date(void) G_GNUC_PURE; | |
147 | |
148 /** | |
149 * Looks for %n, %d, or %t in a string, and replaces them with the | |
150 * specified name, date, and time, respectively. | |
151 * | |
152 * The returned string is stored in a static buffer, so the result | |
153 * should be g_strdup()'d if it's intended to be used for long. | |
154 * | |
155 * @param str The string that may contain the special variables. | |
156 * @param name The sender name. | |
157 * | |
158 * @return A new string where the special variables are expanded. | |
159 */ | |
160 char *away_subs(const char *str, const char *name); | |
161 | |
162 /** | |
163 * Stylizes the specified text using HTML, according to the current | |
164 * font options. | |
165 * | |
166 * @param text The text to stylize. | |
167 * @param len The intended length of the new buffer. | |
168 * | |
169 * @return A newly allocated string of length @a len, containing the | |
170 * stylized version of @a text. | |
171 * | |
172 * @todo Move this to a UI-specific file. | |
173 */ | |
174 char *stylize(const gchar *text, int len); | |
175 | |
176 /** | |
177 * Shows the usage options for the gaim binary. | |
178 * | |
179 * @param mode @c 0 for full options, or @c 1 for a short summary. | |
180 * @param name The name of the binary. | |
181 * | |
182 * @todo Move this to the binary, when a library is formed. | |
183 */ | |
184 void show_usage(int mode, const char *name); | |
185 | |
186 /**` | |
187 * Returns the user's home directory. | |
188 * | |
189 * @return The user's home directory. | |
190 * | |
191 * @see gaim_user_dir() | |
192 */ | |
193 const gchar *gaim_home_dir(void); | |
194 | |
195 /** | |
196 * Returns the gaim settings directory in the user's home directory. | |
197 * | |
198 * @return The gaim settings directory. | |
199 * | |
200 * @see gaim_home_dir() | |
201 */ | |
202 char *gaim_user_dir(void); | |
203 | |
204 /** | |
205 * Copies a string and replaces all HTML linebreaks with newline characters. | |
206 * | |
207 * @param dest The destination string. | |
208 * @param src The source string. | |
209 * @param dest_len The destination string length. | |
210 * | |
211 * @see strncpy_withhtml() | |
212 * @see strdup_withhtml() | |
213 */ | |
214 void strncpy_nohtml(gchar *dest, const gchar *src, size_t dest_len); | |
215 | |
216 /** | |
217 * Copies a string and replaces all newline characters with HTML linebreaks. | |
218 * | |
219 * @param dest The destination string. | |
220 * @param src The source string. | |
221 * @param dest_len The destination string length. | |
222 * | |
223 * @see strncpy_nohtml() | |
224 * @see strdup_withhtml() | |
225 */ | |
226 void strncpy_withhtml(gchar *dest, const gchar *src, size_t dest_len); | |
227 | |
228 /** | |
229 * Duplicates a string and replaces all newline characters from the | |
230 * source string with HTML linebreaks. | |
231 * | |
232 * @param src The source string. | |
233 * | |
234 * @return The new string. | |
235 * | |
236 * @see strncpy_nohtml() | |
237 * @see strncpy_withhtml() | |
238 */ | |
239 gchar *strdup_withhtml(const gchar *src); | |
240 | |
241 /** | |
242 * Ensures that all linefeeds have a matching carriage return. | |
243 * | |
244 * @param str The source string. | |
245 * | |
246 * @return The string with carriage returns. | |
247 */ | |
5136 | 248 char *add_cr(const char *); |
4890 | 249 |
250 /** | |
251 * Strips all linefeeds from a string. | |
252 * | |
253 * @param str The string to strip linefeeds from. | |
254 */ | |
255 void strip_linefeed(char *str); | |
256 | |
257 /** | |
258 * Builds a time_t from the supplied information. | |
259 * | |
260 * @param year The year. | |
261 * @param month The month. | |
262 * @param day The day. | |
263 * @param hour The hour. | |
264 * @param min The minute. | |
265 * @param sec The second. | |
266 * | |
267 * @return A time_t. | |
268 */ | |
269 time_t get_time(int year, int month, int day, | |
270 int hour, int min, int sec) G_GNUC_CONST; | |
271 | |
272 /** | |
273 * Creates a temporary file and returns a file pointer to it. | |
274 * | |
275 * This is like mkstemp(), but returns a file pointer and uses a | |
276 * pre-set template. It uses the semantics of tempnam() for the | |
277 * directory to use and allocates the space for the file path. | |
278 * | |
279 * The caller is responsible for closing the file and removing it when | |
280 * done, as well as freeing the space pointed to by @a path with | |
281 * g_free(). | |
282 * | |
283 * @param path The returned path to the temp file. | |
284 * | |
285 * @return A file pointer to the temporary file, or @c NULL on failure. | |
286 */ | |
287 FILE *gaim_mkstemp(gchar **path); | |
288 | |
289 /** | |
290 * Acts upon an aim: URI. | |
291 * | |
292 * @param uri The URI. | |
293 * | |
294 * @return The response based off the action in the URI. | |
295 */ | |
296 const char *handle_uri(char *uri); | |
297 | |
298 /* This guy does its best to convert a string to UTF-8 from an unknown | |
299 * encoding by checking the locale and trying some sane defaults ... | |
300 * if everything fails it returns NULL. */ | |
301 | |
302 /** | |
303 * Attempts to convert a string to UTF-8 from an unknown encoding. | |
304 * | |
305 * This function checks the locale and tries sane defaults. | |
306 * | |
307 * @param str The source string. | |
308 * | |
309 * @return The UTF-8 string, or @c NULL if it could not be converted. | |
310 */ | |
311 char *gaim_try_conv_to_utf8(const char *str); | |
312 | |
313 /** | |
314 * Returns the IP address from a socket file descriptor. | |
315 * | |
316 * @param fd The socket file descriptor. | |
317 * | |
318 * @return The IP address, or @c NULL on error. | |
319 */ | |
320 char *gaim_getip_from_fd(int fd); | |
321 | |
322 /** | |
323 * Compares two UTF-8 strings. | |
324 * | |
325 * @param a The first string. | |
326 * @param b The second string. | |
327 * | |
328 * @return -1 if @a is less than @a b. | |
329 * 0 if @a is equal to @a b. | |
330 * 1 if @a is greater than @a b. | |
331 */ | |
332 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b); | |
333 | |
334 #endif /* _GAIM_UTIL_H_ */ |