root / libsylph / utils.h @ 2071
History | View | Annotate | Download (14.1 kB)
| 1 | 528 | hiro | /*
|
|---|---|---|---|
| 2 | 578 | hiro | * LibSylph -- E-Mail client library |
| 3 | 1586 | hiro | * Copyright (C) 1999-2007 Hiroyuki Yamamoto |
| 4 | 528 | hiro | * |
| 5 | 578 | hiro | * This library is free software; you can redistribute it and/or |
| 6 | 578 | hiro | * modify it under the terms of the GNU Lesser General Public |
| 7 | 578 | hiro | * License as published by the Free Software Foundation; either |
| 8 | 578 | hiro | * version 2.1 of the License, or (at your option) any later version. |
| 9 | 528 | hiro | * |
| 10 | 578 | hiro | * This library is distributed in the hope that it will be useful, |
| 11 | 528 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 578 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | 578 | hiro | * Lesser General Public License for more details. |
| 14 | 528 | hiro | * |
| 15 | 578 | hiro | * You should have received a copy of the GNU Lesser General Public |
| 16 | 578 | hiro | * License along with this library; if not, write to the Free Software |
| 17 | 578 | hiro | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | 528 | hiro | */ |
| 19 | 528 | hiro | |
| 20 | 528 | hiro | #ifndef __UTILS_H__
|
| 21 | 528 | hiro | #define __UTILS_H__
|
| 22 | 528 | hiro | |
| 23 | 528 | hiro | #ifdef HAVE_CONFIG_H
|
| 24 | 528 | hiro | # include "config.h" |
| 25 | 528 | hiro | #endif
|
| 26 | 528 | hiro | |
| 27 | 528 | hiro | #include <glib.h> |
| 28 | 528 | hiro | #include <stdio.h> |
| 29 | 528 | hiro | #include <string.h> |
| 30 | 528 | hiro | #include <stdlib.h> |
| 31 | 528 | hiro | #include <unistd.h> |
| 32 | 528 | hiro | #include <sys/types.h> |
| 33 | 528 | hiro | #include <dirent.h> |
| 34 | 528 | hiro | #include <time.h> |
| 35 | 528 | hiro | #if HAVE_ALLOCA_H
|
| 36 | 528 | hiro | # include <alloca.h> |
| 37 | 528 | hiro | #endif
|
| 38 | 528 | hiro | |
| 39 | 528 | hiro | /* Wrappers for C library function that take pathname arguments. */
|
| 40 | 528 | hiro | #if GLIB_CHECK_VERSION(2, 6, 0) |
| 41 | 528 | hiro | # include <glib/gstdio.h> |
| 42 | 528 | hiro | #else
|
| 43 | 528 | hiro | |
| 44 | 528 | hiro | #define g_open open
|
| 45 | 528 | hiro | #define g_rename rename
|
| 46 | 528 | hiro | #define g_mkdir mkdir
|
| 47 | 528 | hiro | #define g_stat stat
|
| 48 | 528 | hiro | #define g_lstat lstat
|
| 49 | 528 | hiro | #define g_unlink unlink
|
| 50 | 528 | hiro | #define g_remove remove
|
| 51 | 528 | hiro | #define g_rmdir rmdir
|
| 52 | 528 | hiro | #define g_fopen fopen
|
| 53 | 528 | hiro | #define g_freopen freopen
|
| 54 | 528 | hiro | |
| 55 | 528 | hiro | #endif /* GLIB_CHECK_VERSION */ |
| 56 | 528 | hiro | |
| 57 | 528 | hiro | #if !GLIB_CHECK_VERSION(2, 7, 0) |
| 58 | 528 | hiro | |
| 59 | 528 | hiro | #ifdef G_OS_UNIX
|
| 60 | 528 | hiro | #define g_chdir chdir
|
| 61 | 528 | hiro | #define g_chmod chmod
|
| 62 | 528 | hiro | #else
|
| 63 | 528 | hiro | gint g_chdir (const gchar *path);
|
| 64 | 528 | hiro | gint g_chmod (const gchar *path,
|
| 65 | 528 | hiro | gint mode); |
| 66 | 528 | hiro | #endif /* G_OS_UNIX */ |
| 67 | 528 | hiro | |
| 68 | 528 | hiro | #endif /* !GLIB_CHECK_VERSION */ |
| 69 | 528 | hiro | |
| 70 | 528 | hiro | /* The AC_CHECK_SIZEOF() in configure fails for some machines.
|
| 71 | 528 | hiro | * we provide some fallback values here */ |
| 72 | 528 | hiro | #if !SIZEOF_UNSIGNED_SHORT
|
| 73 | 528 | hiro | #undef SIZEOF_UNSIGNED_SHORT
|
| 74 | 528 | hiro | #define SIZEOF_UNSIGNED_SHORT 2 |
| 75 | 528 | hiro | #endif
|
| 76 | 528 | hiro | #if !SIZEOF_UNSIGNED_INT
|
| 77 | 528 | hiro | #undef SIZEOF_UNSIGNED_INT
|
| 78 | 528 | hiro | #define SIZEOF_UNSIGNED_INT 4 |
| 79 | 528 | hiro | #endif
|
| 80 | 528 | hiro | #if !SIZEOF_UNSIGNED_LONG
|
| 81 | 528 | hiro | #undef SIZEOF_UNSIGNED_LONG
|
| 82 | 528 | hiro | #define SIZEOF_UNSIGNED_LONG 4 |
| 83 | 528 | hiro | #endif
|
| 84 | 528 | hiro | |
| 85 | 528 | hiro | #ifndef HAVE_U32_TYPEDEF
|
| 86 | 528 | hiro | #undef u32 /* maybe there is a macro with this name */ |
| 87 | 528 | hiro | typedef guint32 u32;
|
| 88 | 528 | hiro | #define HAVE_U32_TYPEDEF
|
| 89 | 528 | hiro | #endif
|
| 90 | 528 | hiro | |
| 91 | 528 | hiro | #ifndef BIG_ENDIAN_HOST
|
| 92 | 528 | hiro | #if (G_BYTE_ORDER == G_BIG_ENDIAN)
|
| 93 | 528 | hiro | #define BIG_ENDIAN_HOST 1 |
| 94 | 528 | hiro | #endif
|
| 95 | 528 | hiro | #endif
|
| 96 | 528 | hiro | |
| 97 | 528 | hiro | #define CHDIR_RETURN_IF_FAIL(dir) \
|
| 98 | 528 | hiro | { \
|
| 99 | 528 | hiro | if (change_dir(dir) < 0) return; \ |
| 100 | 528 | hiro | } |
| 101 | 528 | hiro | |
| 102 | 528 | hiro | #define CHDIR_RETURN_VAL_IF_FAIL(dir, val) \
|
| 103 | 528 | hiro | { \
|
| 104 | 528 | hiro | if (change_dir(dir) < 0) return val; \ |
| 105 | 528 | hiro | } |
| 106 | 528 | hiro | |
| 107 | 528 | hiro | #define Xalloca(ptr, size, iffail) \
|
| 108 | 528 | hiro | { \
|
| 109 | 528 | hiro | if ((ptr = alloca(size)) == NULL) { \ |
| 110 | 528 | hiro | g_warning("can't allocate memory\n"); \
|
| 111 | 528 | hiro | iffail; \ |
| 112 | 528 | hiro | } \ |
| 113 | 528 | hiro | } |
| 114 | 528 | hiro | |
| 115 | 528 | hiro | #define Xstrdup_a(ptr, str, iffail) \
|
| 116 | 528 | hiro | { \
|
| 117 | 528 | hiro | gchar *__tmp; \ |
| 118 | 528 | hiro | \ |
| 119 | 528 | hiro | if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \ |
| 120 | 528 | hiro | g_warning("can't allocate memory\n"); \
|
| 121 | 528 | hiro | iffail; \ |
| 122 | 528 | hiro | } else \
|
| 123 | 528 | hiro | strcpy(__tmp, str); \ |
| 124 | 528 | hiro | \ |
| 125 | 528 | hiro | ptr = __tmp; \ |
| 126 | 528 | hiro | } |
| 127 | 528 | hiro | |
| 128 | 528 | hiro | #define Xstrndup_a(ptr, str, len, iffail) \
|
| 129 | 528 | hiro | { \
|
| 130 | 528 | hiro | gchar *__tmp; \ |
| 131 | 528 | hiro | \ |
| 132 | 528 | hiro | if ((__tmp = alloca(len + 1)) == NULL) { \ |
| 133 | 528 | hiro | g_warning("can't allocate memory\n"); \
|
| 134 | 528 | hiro | iffail; \ |
| 135 | 528 | hiro | } else { \
|
| 136 | 528 | hiro | strncpy(__tmp, str, len); \ |
| 137 | 528 | hiro | __tmp[len] = '\0'; \
|
| 138 | 528 | hiro | } \ |
| 139 | 528 | hiro | \ |
| 140 | 528 | hiro | ptr = __tmp; \ |
| 141 | 528 | hiro | } |
| 142 | 528 | hiro | |
| 143 | 528 | hiro | #define Xstrcat_a(ptr, str1, str2, iffail) \
|
| 144 | 528 | hiro | { \
|
| 145 | 528 | hiro | gchar *__tmp; \ |
| 146 | 528 | hiro | gint len1, len2; \ |
| 147 | 528 | hiro | \ |
| 148 | 528 | hiro | len1 = strlen(str1); \ |
| 149 | 528 | hiro | len2 = strlen(str2); \ |
| 150 | 528 | hiro | if ((__tmp = alloca(len1 + len2 + 1)) == NULL) { \ |
| 151 | 528 | hiro | g_warning("can't allocate memory\n"); \
|
| 152 | 528 | hiro | iffail; \ |
| 153 | 528 | hiro | } else { \
|
| 154 | 528 | hiro | memcpy(__tmp, str1, len1); \ |
| 155 | 528 | hiro | memcpy(__tmp + len1, str2, len2 + 1); \
|
| 156 | 528 | hiro | } \ |
| 157 | 528 | hiro | \ |
| 158 | 528 | hiro | ptr = __tmp; \ |
| 159 | 528 | hiro | } |
| 160 | 528 | hiro | |
| 161 | 528 | hiro | #define AUTORELEASE_STR(str, iffail) \
|
| 162 | 528 | hiro | { \
|
| 163 | 528 | hiro | gchar *__str; \ |
| 164 | 528 | hiro | Xstrdup_a(__str, str, iffail); \ |
| 165 | 528 | hiro | g_free(str); \ |
| 166 | 528 | hiro | str = __str; \ |
| 167 | 528 | hiro | } |
| 168 | 528 | hiro | |
| 169 | 528 | hiro | #define FILE_OP_ERROR(file, func) \
|
| 170 | 528 | hiro | { \
|
| 171 | 528 | hiro | fprintf(stderr, "%s: ", file); \
|
| 172 | 528 | hiro | fflush(stderr); \ |
| 173 | 528 | hiro | perror(func); \ |
| 174 | 528 | hiro | } |
| 175 | 528 | hiro | |
| 176 | 552 | hiro | typedef void (*UIUpdateFunc) (void); |
| 177 | 567 | hiro | typedef void (*ProgressFunc) (gint cur, |
| 178 | 567 | hiro | gint total); |
| 179 | 546 | hiro | typedef gchar * (*QueryPasswordFunc) (const gchar *server, |
| 180 | 546 | hiro | const gchar *user);
|
| 181 | 546 | hiro | typedef void (*LogFunc) (const gchar *str); |
| 182 | 528 | hiro | |
| 183 | 528 | hiro | /* for macro expansion */
|
| 184 | 528 | hiro | #define Str(x) #x |
| 185 | 528 | hiro | #define Xstr(x) Str(x)
|
| 186 | 528 | hiro | |
| 187 | 528 | hiro | void list_free_strings (GList *list);
|
| 188 | 528 | hiro | void slist_free_strings (GSList *list);
|
| 189 | 528 | hiro | |
| 190 | 528 | hiro | void hash_free_strings (GHashTable *table);
|
| 191 | 528 | hiro | void hash_free_value_mem (GHashTable *table);
|
| 192 | 528 | hiro | |
| 193 | 528 | hiro | gint str_case_equal (gconstpointer v, |
| 194 | 528 | hiro | gconstpointer v2); |
| 195 | 528 | hiro | guint str_case_hash (gconstpointer key); |
| 196 | 528 | hiro | |
| 197 | 528 | hiro | void ptr_array_free_strings (GPtrArray *array);
|
| 198 | 528 | hiro | |
| 199 | 528 | hiro | typedef gboolean (*StrFindFunc) (const gchar *haystack, |
| 200 | 528 | hiro | const gchar *needle);
|
| 201 | 528 | hiro | |
| 202 | 528 | hiro | gboolean str_find (const gchar *haystack,
|
| 203 | 528 | hiro | const gchar *needle);
|
| 204 | 528 | hiro | gboolean str_case_find (const gchar *haystack,
|
| 205 | 528 | hiro | const gchar *needle);
|
| 206 | 528 | hiro | gboolean str_find_equal (const gchar *haystack,
|
| 207 | 528 | hiro | const gchar *needle);
|
| 208 | 528 | hiro | gboolean str_case_find_equal (const gchar *haystack,
|
| 209 | 528 | hiro | const gchar *needle);
|
| 210 | 528 | hiro | |
| 211 | 528 | hiro | /* number-string conversion */
|
| 212 | 528 | hiro | gint to_number (const gchar *nstr);
|
| 213 | 528 | hiro | gchar *itos_buf (gchar *nstr, |
| 214 | 528 | hiro | gint n); |
| 215 | 528 | hiro | gchar *itos (gint n); |
| 216 | 742 | hiro | gchar *to_human_readable (gint64 size); |
| 217 | 528 | hiro | |
| 218 | 528 | hiro | /* alternative string functions */
|
| 219 | 528 | hiro | gint strcmp2 (const gchar *s1,
|
| 220 | 528 | hiro | const gchar *s2);
|
| 221 | 528 | hiro | gint path_cmp (const gchar *s1,
|
| 222 | 528 | hiro | const gchar *s2);
|
| 223 | 528 | hiro | gchar *strretchomp (gchar *str); |
| 224 | 528 | hiro | gchar *strtailchomp (gchar *str, |
| 225 | 528 | hiro | gchar tail_char); |
| 226 | 528 | hiro | gchar *strcrchomp (gchar *str); |
| 227 | 528 | hiro | gchar *strcasestr (const gchar *haystack,
|
| 228 | 528 | hiro | const gchar *needle);
|
| 229 | 528 | hiro | gpointer my_memmem (gconstpointer haystack, |
| 230 | 528 | hiro | size_t haystacklen, |
| 231 | 528 | hiro | gconstpointer needle, |
| 232 | 528 | hiro | size_t needlelen); |
| 233 | 528 | hiro | gchar *strncpy2 (gchar *dest, |
| 234 | 528 | hiro | const gchar *src,
|
| 235 | 528 | hiro | size_t n); |
| 236 | 528 | hiro | |
| 237 | 642 | hiro | gboolean str_has_suffix_case (const gchar *str,
|
| 238 | 642 | hiro | const gchar *suffix);
|
| 239 | 528 | hiro | |
| 240 | 1035 | hiro | gint str_find_format_times (const gchar *haystack,
|
| 241 | 1035 | hiro | gchar ch); |
| 242 | 1035 | hiro | |
| 243 | 642 | hiro | gboolean is_next_nonascii (const gchar *s);
|
| 244 | 642 | hiro | gint get_next_word_len (const gchar *s);
|
| 245 | 642 | hiro | |
| 246 | 528 | hiro | /* functions for string parsing */
|
| 247 | 528 | hiro | gint subject_compare (const gchar *s1,
|
| 248 | 528 | hiro | const gchar *s2);
|
| 249 | 528 | hiro | gint subject_compare_for_sort (const gchar *s1,
|
| 250 | 528 | hiro | const gchar *s2);
|
| 251 | 528 | hiro | void trim_subject_for_compare (gchar *str);
|
| 252 | 528 | hiro | void trim_subject_for_sort (gchar *str);
|
| 253 | 528 | hiro | void trim_subject (gchar *str);
|
| 254 | 528 | hiro | void eliminate_parenthesis (gchar *str,
|
| 255 | 528 | hiro | gchar op, |
| 256 | 528 | hiro | gchar cl); |
| 257 | 528 | hiro | void extract_parenthesis (gchar *str,
|
| 258 | 528 | hiro | gchar op, |
| 259 | 528 | hiro | gchar cl); |
| 260 | 1694 | hiro | void extract_parenthesis_with_escape (gchar *str,
|
| 261 | 1694 | hiro | gchar op, |
| 262 | 1694 | hiro | gchar cl); |
| 263 | 528 | hiro | |
| 264 | 528 | hiro | void extract_parenthesis_with_skip_quote (gchar *str,
|
| 265 | 528 | hiro | gchar quote_chr, |
| 266 | 528 | hiro | gchar op, |
| 267 | 528 | hiro | gchar cl); |
| 268 | 528 | hiro | |
| 269 | 528 | hiro | void eliminate_quote (gchar *str,
|
| 270 | 528 | hiro | gchar quote_chr); |
| 271 | 528 | hiro | void extract_quote (gchar *str,
|
| 272 | 528 | hiro | gchar quote_chr); |
| 273 | 1694 | hiro | void extract_quote_with_escape (gchar *str,
|
| 274 | 1694 | hiro | gchar quote_chr); |
| 275 | 528 | hiro | void eliminate_address_comment (gchar *str);
|
| 276 | 528 | hiro | gchar *strchr_with_skip_quote (const gchar *str,
|
| 277 | 528 | hiro | gint quote_chr, |
| 278 | 528 | hiro | gint c); |
| 279 | 528 | hiro | gchar *strrchr_with_skip_quote (const gchar *str,
|
| 280 | 528 | hiro | gint quote_chr, |
| 281 | 528 | hiro | gint c); |
| 282 | 528 | hiro | void extract_address (gchar *str);
|
| 283 | 528 | hiro | void extract_list_id_str (gchar *str);
|
| 284 | 528 | hiro | |
| 285 | 581 | hiro | gchar *normalize_address_field (const gchar *str);
|
| 286 | 581 | hiro | |
| 287 | 688 | hiro | gboolean address_equal (const gchar *addr1,
|
| 288 | 688 | hiro | const gchar *addr2);
|
| 289 | 688 | hiro | |
| 290 | 581 | hiro | GSList *address_list_append_orig (GSList *addr_list, |
| 291 | 581 | hiro | const gchar *str);
|
| 292 | 528 | hiro | GSList *address_list_append (GSList *addr_list, |
| 293 | 528 | hiro | const gchar *str);
|
| 294 | 528 | hiro | GSList *references_list_prepend (GSList *msgid_list, |
| 295 | 528 | hiro | const gchar *str);
|
| 296 | 528 | hiro | GSList *references_list_append (GSList *msgid_list, |
| 297 | 528 | hiro | const gchar *str);
|
| 298 | 528 | hiro | GSList *newsgroup_list_append (GSList *group_list, |
| 299 | 528 | hiro | const gchar *str);
|
| 300 | 528 | hiro | |
| 301 | 528 | hiro | GList *add_history (GList *list, |
| 302 | 528 | hiro | const gchar *str);
|
| 303 | 528 | hiro | |
| 304 | 1058 | hiro | /* modify string */
|
| 305 | 528 | hiro | void remove_return (gchar *str);
|
| 306 | 528 | hiro | void remove_space (gchar *str);
|
| 307 | 528 | hiro | void unfold_line (gchar *str);
|
| 308 | 528 | hiro | void subst_char (gchar *str,
|
| 309 | 528 | hiro | gchar orig, |
| 310 | 528 | hiro | gchar subst); |
| 311 | 528 | hiro | void subst_chars (gchar *str,
|
| 312 | 528 | hiro | gchar *orig, |
| 313 | 528 | hiro | gchar subst); |
| 314 | 528 | hiro | void subst_null (gchar *str,
|
| 315 | 528 | hiro | gint len, |
| 316 | 528 | hiro | gchar subst); |
| 317 | 1058 | hiro | void subst_control (gchar *str,
|
| 318 | 1058 | hiro | gchar subst); |
| 319 | 528 | hiro | void subst_for_filename (gchar *str);
|
| 320 | 601 | hiro | |
| 321 | 601 | hiro | gchar *get_alt_filename (const gchar *filename,
|
| 322 | 601 | hiro | gint count); |
| 323 | 601 | hiro | |
| 324 | 528 | hiro | gboolean is_header_line (const gchar *str);
|
| 325 | 528 | hiro | gboolean is_ascii_str (const gchar *str);
|
| 326 | 601 | hiro | |
| 327 | 528 | hiro | gint get_quote_level (const gchar *str);
|
| 328 | 528 | hiro | gint check_line_length (const gchar *str,
|
| 329 | 528 | hiro | gint max_chars, |
| 330 | 528 | hiro | gint *line); |
| 331 | 528 | hiro | |
| 332 | 528 | hiro | gchar *strstr_with_skip_quote (const gchar *haystack,
|
| 333 | 528 | hiro | const gchar *needle);
|
| 334 | 528 | hiro | gchar *strchr_parenthesis_close (const gchar *str,
|
| 335 | 528 | hiro | gchar op, |
| 336 | 528 | hiro | gchar cl); |
| 337 | 528 | hiro | |
| 338 | 528 | hiro | gchar **strsplit_parenthesis (const gchar *str,
|
| 339 | 528 | hiro | gchar op, |
| 340 | 528 | hiro | gchar cl, |
| 341 | 528 | hiro | gint max_tokens); |
| 342 | 528 | hiro | gchar **strsplit_with_quote (const gchar *str,
|
| 343 | 528 | hiro | const gchar *delim,
|
| 344 | 528 | hiro | gint max_tokens); |
| 345 | 1616 | hiro | gchar **strsplit_csv (const gchar *str,
|
| 346 | 1616 | hiro | gchar delim, |
| 347 | 1616 | hiro | gint max_tokens); |
| 348 | 528 | hiro | |
| 349 | 528 | hiro | gchar *get_abbrev_newsgroup_name (const gchar *group,
|
| 350 | 528 | hiro | gint len); |
| 351 | 528 | hiro | gchar *trim_string (const gchar *str,
|
| 352 | 528 | hiro | gint len); |
| 353 | 528 | hiro | gchar *trim_string_before (const gchar *str,
|
| 354 | 528 | hiro | gint len); |
| 355 | 528 | hiro | |
| 356 | 528 | hiro | GList *uri_list_extract_filenames (const gchar *uri_list);
|
| 357 | 528 | hiro | gboolean is_uri_string (const gchar *str);
|
| 358 | 528 | hiro | gchar *get_uri_path (const gchar *uri);
|
| 359 | 528 | hiro | gint get_uri_len (const gchar *str);
|
| 360 | 528 | hiro | void decode_uri (gchar *decoded_uri,
|
| 361 | 528 | hiro | const gchar *encoded_uri);
|
| 362 | 1052 | hiro | void decode_xdigit_encoded_str (gchar *decoded,
|
| 363 | 1052 | hiro | const gchar *encoded);
|
| 364 | 528 | hiro | gchar *encode_uri (const gchar *filename);
|
| 365 | 1003 | hiro | gchar *uriencode_for_filename (const gchar *filename);
|
| 366 | 1709 | hiro | gchar *uriencode_for_mailto (const gchar *mailto);
|
| 367 | 528 | hiro | gint scan_mailto_url (const gchar *mailto,
|
| 368 | 528 | hiro | gchar **to, |
| 369 | 528 | hiro | gchar **cc, |
| 370 | 528 | hiro | gchar **bcc, |
| 371 | 528 | hiro | gchar **subject, |
| 372 | 1586 | hiro | gchar **inreplyto, |
| 373 | 528 | hiro | gchar **body); |
| 374 | 528 | hiro | |
| 375 | 667 | hiro | void set_startup_dir (void); |
| 376 | 667 | hiro | void set_rc_dir (const gchar *dir); |
| 377 | 667 | hiro | |
| 378 | 528 | hiro | /* return static strings */
|
| 379 | 667 | hiro | const gchar *get_startup_dir (void); |
| 380 | 528 | hiro | const gchar *get_home_dir (void); |
| 381 | 1300 | hiro | const gchar *get_document_dir (void); |
| 382 | 528 | hiro | const gchar *get_rc_dir (void); |
| 383 | 528 | hiro | const gchar *get_old_rc_dir (void); |
| 384 | 528 | hiro | const gchar *get_mail_base_dir (void); |
| 385 | 528 | hiro | const gchar *get_news_cache_dir (void); |
| 386 | 528 | hiro | const gchar *get_imap_cache_dir (void); |
| 387 | 528 | hiro | const gchar *get_mime_tmp_dir (void); |
| 388 | 528 | hiro | const gchar *get_template_dir (void); |
| 389 | 528 | hiro | const gchar *get_tmp_dir (void); |
| 390 | 528 | hiro | gchar *get_tmp_file (void);
|
| 391 | 528 | hiro | const gchar *get_domain_name (void); |
| 392 | 528 | hiro | |
| 393 | 528 | hiro | /* file / directory handling */
|
| 394 | 528 | hiro | off_t get_file_size (const gchar *file);
|
| 395 | 528 | hiro | off_t get_file_size_as_crlf (const gchar *file);
|
| 396 | 528 | hiro | off_t get_left_file_size (FILE *fp); |
| 397 | 528 | hiro | |
| 398 | 528 | hiro | gboolean file_exist (const gchar *file,
|
| 399 | 528 | hiro | gboolean allow_fifo); |
| 400 | 528 | hiro | gboolean is_dir_exist (const gchar *dir);
|
| 401 | 528 | hiro | gboolean is_file_entry_exist (const gchar *file);
|
| 402 | 528 | hiro | gboolean dirent_is_regular_file (struct dirent *d);
|
| 403 | 528 | hiro | gboolean dirent_is_directory (struct dirent *d);
|
| 404 | 528 | hiro | |
| 405 | 528 | hiro | #define is_file_exist(file) file_exist(file, FALSE)
|
| 406 | 528 | hiro | #define is_file_or_fifo_exist(file) file_exist(file, TRUE)
|
| 407 | 528 | hiro | |
| 408 | 528 | hiro | gint change_dir (const gchar *dir);
|
| 409 | 528 | hiro | gint make_dir (const gchar *dir);
|
| 410 | 528 | hiro | gint make_dir_hier (const gchar *dir);
|
| 411 | 528 | hiro | gint remove_all_files (const gchar *dir);
|
| 412 | 528 | hiro | gint remove_numbered_files (const gchar *dir,
|
| 413 | 528 | hiro | guint first, |
| 414 | 528 | hiro | guint last); |
| 415 | 528 | hiro | gint remove_all_numbered_files (const gchar *dir);
|
| 416 | 528 | hiro | gint remove_expired_files (const gchar *dir,
|
| 417 | 528 | hiro | guint hours); |
| 418 | 528 | hiro | gint remove_dir_recursive (const gchar *dir);
|
| 419 | 528 | hiro | gint rename_force (const gchar *oldpath,
|
| 420 | 528 | hiro | const gchar *newpath);
|
| 421 | 528 | hiro | gint copy_file (const gchar *src,
|
| 422 | 528 | hiro | const gchar *dest,
|
| 423 | 528 | hiro | gboolean keep_backup); |
| 424 | 528 | hiro | gint copy_dir (const gchar *src,
|
| 425 | 528 | hiro | const gchar *dest);
|
| 426 | 528 | hiro | gint move_file (const gchar *src,
|
| 427 | 528 | hiro | const gchar *dest,
|
| 428 | 528 | hiro | gboolean overwrite); |
| 429 | 528 | hiro | gint copy_file_part (FILE *fp, |
| 430 | 528 | hiro | off_t offset, |
| 431 | 528 | hiro | size_t length, |
| 432 | 528 | hiro | const gchar *dest);
|
| 433 | 528 | hiro | |
| 434 | 528 | hiro | gchar *canonicalize_str (const gchar *str);
|
| 435 | 528 | hiro | gint canonicalize_file (const gchar *src,
|
| 436 | 528 | hiro | const gchar *dest);
|
| 437 | 528 | hiro | gint canonicalize_file_replace (const gchar *file);
|
| 438 | 800 | hiro | FILE *canonicalize_file_stream (FILE *fp, |
| 439 | 800 | hiro | gint *length); |
| 440 | 528 | hiro | gint uncanonicalize_file (const gchar *src,
|
| 441 | 528 | hiro | const gchar *dest);
|
| 442 | 528 | hiro | gint uncanonicalize_file_replace(const gchar *file);
|
| 443 | 528 | hiro | |
| 444 | 528 | hiro | gchar *normalize_newlines (const gchar *str);
|
| 445 | 1169 | hiro | gchar *strchomp_all (const gchar *str);
|
| 446 | 528 | hiro | |
| 447 | 771 | hiro | FILE *get_outgoing_rfc2822_file (FILE *fp); |
| 448 | 528 | hiro | gchar *get_outgoing_rfc2822_str (FILE *fp); |
| 449 | 528 | hiro | gchar *generate_mime_boundary (const gchar *prefix);
|
| 450 | 528 | hiro | |
| 451 | 528 | hiro | gint change_file_mode_rw (FILE *fp, |
| 452 | 528 | hiro | const gchar *file);
|
| 453 | 528 | hiro | FILE *my_tmpfile (void);
|
| 454 | 528 | hiro | FILE *str_open_as_stream (const gchar *str);
|
| 455 | 528 | hiro | gint str_write_to_file (const gchar *str,
|
| 456 | 528 | hiro | const gchar *file);
|
| 457 | 528 | hiro | gchar *file_read_to_str (const gchar *file);
|
| 458 | 528 | hiro | gchar *file_read_stream_to_str (FILE *fp); |
| 459 | 528 | hiro | |
| 460 | 528 | hiro | /* process execution */
|
| 461 | 528 | hiro | gint execute_async (gchar *const argv[]);
|
| 462 | 528 | hiro | gint execute_sync (gchar *const argv[]);
|
| 463 | 528 | hiro | gint execute_command_line (const gchar *cmdline,
|
| 464 | 528 | hiro | gboolean async); |
| 465 | 642 | hiro | gint execute_open_file (const gchar *file,
|
| 466 | 642 | hiro | const gchar *content_type);
|
| 467 | 680 | hiro | gint execute_print_file (const gchar *file);
|
| 468 | 528 | hiro | gchar *get_command_output (const gchar *cmdline);
|
| 469 | 528 | hiro | |
| 470 | 528 | hiro | /* open URI with external browser */
|
| 471 | 528 | hiro | gint open_uri(const gchar *uri, const gchar *cmdline); |
| 472 | 528 | hiro | |
| 473 | 528 | hiro | /* time functions */
|
| 474 | 528 | hiro | time_t remote_tzoffset_sec (const gchar *zone);
|
| 475 | 528 | hiro | time_t tzoffset_sec (time_t *now); |
| 476 | 528 | hiro | gchar *tzoffset (time_t *now); |
| 477 | 528 | hiro | void get_rfc822_date (gchar *buf,
|
| 478 | 528 | hiro | gint len); |
| 479 | 528 | hiro | |
| 480 | 528 | hiro | size_t my_strftime (gchar *s, |
| 481 | 528 | hiro | size_t max, |
| 482 | 528 | hiro | const gchar *format,
|
| 483 | 528 | hiro | const struct tm *tm); |
| 484 | 528 | hiro | |
| 485 | 552 | hiro | /* UI hints */
|
| 486 | 552 | hiro | void set_ui_update_func (UIUpdateFunc func);
|
| 487 | 567 | hiro | void ui_update (void); |
| 488 | 552 | hiro | |
| 489 | 567 | hiro | void set_progress_func (ProgressFunc func);
|
| 490 | 567 | hiro | void progress_show (gint cur,
|
| 491 | 567 | hiro | gint total); |
| 492 | 567 | hiro | |
| 493 | 546 | hiro | /* user input */
|
| 494 | 546 | hiro | void set_input_query_password_func (QueryPasswordFunc func);
|
| 495 | 546 | hiro | |
| 496 | 546 | hiro | gchar *input_query_password (const gchar *server,
|
| 497 | 546 | hiro | const gchar *user);
|
| 498 | 546 | hiro | |
| 499 | 528 | hiro | /* logging */
|
| 500 | 528 | hiro | void set_log_file (const gchar *filename); |
| 501 | 528 | hiro | void close_log_file (void); |
| 502 | 528 | hiro | void set_log_verbosity (gboolean verbose);
|
| 503 | 528 | hiro | gboolean get_debug_mode (void);
|
| 504 | 528 | hiro | void set_debug_mode (gboolean enable);
|
| 505 | 528 | hiro | |
| 506 | 528 | hiro | void set_log_ui_func (LogFunc print_func,
|
| 507 | 528 | hiro | LogFunc message_func, |
| 508 | 528 | hiro | LogFunc warning_func, |
| 509 | 528 | hiro | LogFunc error_func); |
| 510 | 528 | hiro | |
| 511 | 528 | hiro | void set_log_show_status_func (LogFunc status_func);
|
| 512 | 528 | hiro | |
| 513 | 528 | hiro | void debug_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2); |
| 514 | 554 | hiro | void status_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2); |
| 515 | 546 | hiro | |
| 516 | 631 | hiro | void log_write (const gchar *str, |
| 517 | 631 | hiro | const gchar *prefix);
|
| 518 | 631 | hiro | |
| 519 | 528 | hiro | void log_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2); |
| 520 | 528 | hiro | void log_message (const gchar *format, ...) G_GNUC_PRINTF(1, 2); |
| 521 | 528 | hiro | void log_warning (const gchar *format, ...) G_GNUC_PRINTF(1, 2); |
| 522 | 528 | hiro | void log_error (const gchar *format, ...) G_GNUC_PRINTF(1, 2); |
| 523 | 528 | hiro | |
| 524 | 528 | hiro | #endif /* __UTILS_H__ */ |