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