2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <sys/types.h>
42 /* The AC_CHECK_SIZEOF() in configure fails for some machines.
43 * we provide some fallback values here */
44 #if !SIZEOF_UNSIGNED_SHORT
45 #undef SIZEOF_UNSIGNED_SHORT
46 #define SIZEOF_UNSIGNED_SHORT 2
48 #if !SIZEOF_UNSIGNED_INT
49 #undef SIZEOF_UNSIGNED_INT
50 #define SIZEOF_UNSIGNED_INT 4
52 #if !SIZEOF_UNSIGNED_LONG
53 #undef SIZEOF_UNSIGNED_LONG
54 #define SIZEOF_UNSIGNED_LONG 4
57 #ifndef HAVE_U32_TYPEDEF
58 #undef u32 /* maybe there is a macro with this name */
60 #define HAVE_U32_TYPEDEF
63 #ifndef BIG_ENDIAN_HOST
64 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
65 #define BIG_ENDIAN_HOST 1
69 #define CHDIR_RETURN_IF_FAIL(dir) \
71 if (change_dir(dir) < 0) return; \
74 #define CHDIR_RETURN_VAL_IF_FAIL(dir, val) \
76 if (change_dir(dir) < 0) return val; \
79 #define Xalloca(ptr, size, iffail) \
81 if ((ptr = alloca(size)) == NULL) { \
82 g_warning("can't allocate memory\n"); \
87 #define Xstrdup_a(ptr, str, iffail) \
91 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
92 g_warning("can't allocate memory\n"); \
100 #define Xstrndup_a(ptr, str, len, iffail) \
104 if ((__tmp = alloca(len + 1)) == NULL) { \
105 g_warning("can't allocate memory\n"); \
108 strncpy(__tmp, str, len); \
115 #define Xstrcat_a(ptr, str1, str2, iffail) \
120 len1 = strlen(str1); \
121 len2 = strlen(str2); \
122 if ((__tmp = alloca(len1 + len2 + 1)) == NULL) { \
123 g_warning("can't allocate memory\n"); \
126 memcpy(__tmp, str1, len1); \
127 memcpy(__tmp + len1, str2, len2 + 1); \
133 #define FILE_OP_ERROR(file, func) \
135 fprintf(stderr, "%s: ", file); \
139 typedef gpointer (*GNodeMapFunc) (gpointer nodedata, gpointer data);
141 /* debug functions */
142 void debug_set_mode (gboolean mode);
143 gboolean debug_get_mode (void);
144 #define debug_print \
145 debug_print_real(__FILE__ ":%d:", __LINE__), \
148 /* for macro expansion */
150 #define Xstr(x) Str(x)
152 void list_free_strings (GList *list);
153 void slist_free_strings (GSList *list);
155 void hash_free_strings (GHashTable *table);
156 void hash_free_value_mem (GHashTable *table);
158 gint str_case_equal (gconstpointer v,
160 guint str_case_hash (gconstpointer key);
162 void ptr_array_free_strings (GPtrArray *array);
164 /* number-string conversion */
165 gint to_number (const gchar *nstr);
166 gchar *itos_buf (gchar *nstr,
168 gchar *itos (gint n);
169 gchar *to_human_readable (off_t size);
171 /* alternative string functions */
172 gint strcmp2 (const gchar *s1,
174 gchar *strstr2 (const gchar *s1,
176 gint path_cmp (const gchar *s1,
178 gchar *strretchomp (gchar *str);
179 gchar *strtailchomp (gchar *str,
181 gchar *strcrchomp (gchar *str);
182 gchar *strcasestr (const gchar *haystack,
183 const gchar *needle);
184 gchar *strncpy2 (gchar *dest,
188 /* wide-character functions */
190 int iswalnum (wint_t wc);
193 int iswspace (wint_t wc);
196 wint_t towlower (wint_t wc);
200 size_t wcslen (const wchar_t *s);
203 wchar_t *wcscpy (wchar_t *dest,
207 wchar_t *wcsncpy (wchar_t *dest,
212 wchar_t *wcsdup (const wchar_t *s);
213 wchar_t *wcsndup (const wchar_t *s,
215 wchar_t *strdup_mbstowcs (const gchar *s);
216 gchar *strdup_wcstombs (const wchar_t *s);
217 gint wcsncasecmp (const wchar_t *s1,
220 wchar_t *wcscasestr (const wchar_t *haystack,
221 const wchar_t *needle);
222 gint get_mbs_len (const gchar *s);
224 gboolean is_next_nonascii (const guchar *s);
225 gint get_next_word_len (const gchar *s);
227 /* functions for string parsing */
228 gint subject_compare (const gchar *s1,
230 gint subject_compare_for_sort (const gchar *s1,
232 void trim_subject_for_compare (gchar *str);
233 void trim_subject_for_sort (gchar *str);
234 void trim_subject (gchar *str);
235 void eliminate_parenthesis (gchar *str,
238 void extract_parenthesis (gchar *str,
242 void extract_parenthesis_with_skip_quote (gchar *str,
247 void eliminate_quote (gchar *str,
249 void extract_quote (gchar *str,
251 void eliminate_address_comment (gchar *str);
252 gchar *strchr_with_skip_quote (const gchar *str,
255 gchar *strrchr_with_skip_quote (const gchar *str,
258 void extract_address (gchar *str);
259 void extract_list_id_str (gchar *str);
261 GSList *slist_concat_unique (GSList *first,
263 GSList *address_list_append (GSList *addr_list,
265 GSList *address_list_append_with_comments(GSList *addr_list,
267 GSList *references_list_append (GSList *msgid_list,
269 GSList *newsgroup_list_append (GSList *group_list,
272 GList *add_history (GList *list,
275 void remove_return (gchar *str);
276 void remove_space (gchar *str);
277 void unfold_line (gchar *str);
278 void subst_char (gchar *str,
281 void subst_chars (gchar *str,
284 void subst_for_filename (gchar *str);
285 void subst_for_shellsafe_filename (gchar *str);
286 gboolean is_header_line (const gchar *str);
287 gboolean is_ascii_str (const guchar *str);
288 gint get_quote_level (const gchar *str,
289 const gchar *quote_chars);
290 gchar *strstr_with_skip_quote (const gchar *haystack,
291 const gchar *needle);
292 gchar *strchr_parenthesis_close (const gchar *str,
296 gchar **strsplit_parenthesis (const gchar *str,
300 gchar **strsplit_with_quote (const gchar *str,
304 gchar *get_abbrev_newsgroup_name (const gchar *group,
306 gchar *trim_string (const gchar *str,
309 GList *uri_list_extract_filenames (const gchar *uri_list);
310 void decode_uri (gchar *decoded_uri,
311 const gchar *encoded_uri);
312 gint scan_mailto_url (const gchar *mailto,
319 /* return static strings */
320 gchar *get_home_dir (void);
321 gchar *get_rc_dir (void);
322 gchar *get_news_cache_dir (void);
323 gchar *get_imap_cache_dir (void);
324 gchar *get_mbox_cache_dir (void);
325 gchar *get_mime_tmp_dir (void);
326 gchar *get_template_dir (void);
327 gchar *get_header_cache_dir (void);
328 gchar *get_tmp_dir (void);
329 gchar *get_tmp_file (void);
330 gchar *get_domain_name (void);
332 /* file / directory handling */
333 off_t get_file_size (const gchar *file);
334 off_t get_file_size_as_crlf (const gchar *file);
335 off_t get_left_file_size (FILE *fp);
337 gboolean file_exist (const gchar *file,
338 gboolean allow_fifo);
339 gboolean is_dir_exist (const gchar *dir);
340 gboolean is_file_entry_exist (const gchar *file);
341 gboolean dirent_is_regular_file (struct dirent *d);
342 gboolean dirent_is_directory (struct dirent *d);
344 #define is_file_exist(file) file_exist(file, FALSE)
345 #define is_file_or_fifo_exist(file) file_exist(file, TRUE)
347 gint change_dir (const gchar *dir);
348 gint make_dir (const gchar *dir);
349 gint make_dir_hier (const gchar *dir);
350 gint remove_all_files (const gchar *dir);
351 gint remove_numbered_files (const gchar *dir,
354 gint remove_numbered_files_not_in_list(const gchar *dir,
356 gint remove_all_numbered_files (const gchar *dir);
357 gint remove_expired_files (const gchar *dir,
359 gint remove_dir_recursive (const gchar *dir);
360 gint append_file (const gchar *src,
362 gboolean keep_backup);
363 gint copy_file (const gchar *src,
365 gboolean keep_backup);
366 gint move_file (const gchar *src,
369 gint copy_file_part (FILE *fp,
374 gchar *canonicalize_str (const gchar *str);
375 gint canonicalize_file (const gchar *src,
377 gint canonicalize_file_replace (const gchar *file);
378 gint uncanonicalize_file (const gchar *src,
380 gint uncanonicalize_file_replace(const gchar *file);
382 gchar *normalize_newlines (const gchar *str);
384 gchar *get_outgoing_rfc2822_str (FILE *fp);
386 gint change_file_mode_rw (FILE *fp,
388 FILE *my_tmpfile (void);
389 FILE *get_tmpfile_in_dir (const gchar *dir,
391 FILE *str_open_as_stream (const gchar *str);
392 gint str_write_to_file (const gchar *str,
394 gchar *file_read_to_str (const gchar *file);
395 gchar *file_read_stream_to_str (FILE *fp);
397 /* process execution */
398 gint execute_async (gchar *const argv[]);
399 gint execute_sync (gchar *const argv[]);
400 gint execute_command_line (const gchar *cmdline,
402 gchar *get_command_output (const gchar *cmdline);
404 /* open URI with external browser */
405 gint open_uri(const gchar *uri, const gchar *cmdline);
408 time_t remote_tzoffset_sec (const gchar *zone);
409 time_t tzoffset_sec (time_t *now);
410 gchar *tzoffset (time_t *now);
411 void get_rfc822_date (gchar *buf,
415 void debug_print_real (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
417 /* subject threading */
418 void * subject_table_lookup(GHashTable *subject_table, gchar * subject);
419 void subject_table_insert(GHashTable *subject_table, gchar * subject,
421 void subject_table_remove(GHashTable *subject_table, gchar * subject);
422 gint subject_get_prefix_length (const gchar *subject);
424 /* quoting recognition */
425 const gchar * line_has_quote_char (const gchar *str,
426 const gchar *quote_chars);
427 const gchar * line_has_quote_char_last (const gchar *str,
428 const gchar *quote_chars);
430 /* used in extended search */
431 gchar * expand_search_string (const gchar *str);
433 guint g_stricase_hash (gconstpointer gptr);
434 gint g_stricase_equal (gconstpointer gptr1, gconstpointer gptr2);
435 gint g_int_compare (gconstpointer a, gconstpointer b);
437 gchar *generate_msgid (const gchar *address, gchar *buf, gint len);
438 gchar *generate_mime_boundary (const gchar *prefix);
440 gint quote_cmd_argument(gchar * result, guint size,
442 GNode *g_node_map(GNode *node, GNodeMapFunc func, gpointer data);
444 #endif /* __UTILS_H__ */