2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 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>
41 /* The AC_CHECK_SIZEOF() in configure fails for some machines.
42 * we provide some fallback values here */
43 #if !SIZEOF_UNSIGNED_SHORT
44 #undef SIZEOF_UNSIGNED_SHORT
45 #define SIZEOF_UNSIGNED_SHORT 2
47 #if !SIZEOF_UNSIGNED_INT
48 #undef SIZEOF_UNSIGNED_INT
49 #define SIZEOF_UNSIGNED_INT 4
51 #if !SIZEOF_UNSIGNED_LONG
52 #undef SIZEOF_UNSIGNED_LONG
53 #define SIZEOF_UNSIGNED_LONG 4
56 #ifndef HAVE_U32_TYPEDEF
57 #undef u32 /* maybe there is a macro with this name */
59 #define HAVE_U32_TYPEDEF
62 #ifndef BIG_ENDIAN_HOST
63 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
64 #define BIG_ENDIAN_HOST 1
68 #define CHDIR_RETURN_IF_FAIL(dir) \
70 if (change_dir(dir) < 0) return; \
73 #define CHDIR_RETURN_VAL_IF_FAIL(dir, val) \
75 if (change_dir(dir) < 0) return val; \
78 #define Xalloca(ptr, size, iffail) \
80 if ((ptr = alloca(size)) == NULL) { \
81 g_warning("can't allocate memory\n"); \
86 #define Xstrdup_a(ptr, str, iffail) \
90 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
91 g_warning("can't allocate memory\n"); \
99 #define Xstrndup_a(ptr, str, len, iffail) \
103 if ((__tmp = alloca(len + 1)) == NULL) { \
104 g_warning("can't allocate memory\n"); \
107 strncpy(__tmp, str, len); \
114 #define FILE_OP_ERROR(file, func) \
116 fprintf(stderr, "%s: ", file); \
120 #define debug_print \
121 debug_print_real(__FILE__ ":%d:", __LINE__), \
124 /* for macro expansion */
126 #define Xstr(x) Str(x)
128 void list_free_strings (GList *list);
129 void slist_free_strings (GSList *list);
131 void hash_free_strings (GHashTable *table);
132 void hash_free_value_mem (GHashTable *table);
134 void ptr_array_free_strings (GPtrArray *array);
136 /* number-string conversion */
137 gint to_number (const gchar *nstr);
138 gchar *itos_buf (gchar *nstr,
140 gchar *itos (gint n);
141 gchar *to_human_readable (off_t size);
143 /* alternative string functions */
144 gint strcmp2 (const gchar *s1,
146 gchar *strstr2 (const gchar *s1,
148 gint path_cmp (const gchar *s1,
150 gchar *strretchomp (gchar *str);
151 gchar *strtailchomp (gchar *str,
153 gchar *strcrchomp (gchar *str);
154 gchar *strcasestr (const gchar *haystack,
155 const gchar *needle);
156 gchar *strncpy2 (gchar *dest,
160 /* wide-character functions */
162 int iswalnum (wint_t wc);
165 int iswspace (wint_t wc);
168 wint_t towlower (wint_t wc);
172 size_t wcslen (const wchar_t *s);
175 wchar_t *wcscpy (wchar_t *dest,
179 wchar_t *wcsncpy (wchar_t *dest,
184 wchar_t *wcsdup (const wchar_t *s);
185 wchar_t *wcsndup (const wchar_t *s,
187 wchar_t *strdup_mbstowcs (const gchar *s);
188 gchar *strdup_wcstombs (const wchar_t *s);
189 gint wcsncasecmp (const wchar_t *s1,
192 wchar_t *wcscasestr (const wchar_t *haystack,
193 const wchar_t *needle);
195 gboolean is_next_nonascii (const wchar_t *s);
196 gboolean is_next_mbs (const wchar_t *s);
197 wchar_t *find_wspace (const wchar_t *s);
199 /* functions for string parsing */
200 gint subject_compare (const gchar *s1,
202 void trim_subject (gchar *str);
203 void eliminate_parenthesis (gchar *str,
206 void extract_parenthesis (gchar *str,
210 void extract_one_parenthesis_with_skip_quote (gchar *str,
214 void extract_parenthesis_with_skip_quote (gchar *str,
219 void eliminate_quote (gchar *str,
221 void extract_quote (gchar *str,
223 void eliminate_address_comment (gchar *str);
224 gchar *strchr_with_skip_quote (const gchar *str,
227 gchar *strrchr_with_skip_quote (const gchar *str,
230 void extract_address (gchar *str);
232 GSList *address_list_append (GSList *addr_list,
234 GSList *references_list_append (GSList *msgid_list,
236 GSList *newsgroup_list_append (GSList *group_list,
239 GList *add_history (GList *list,
242 void remove_return (gchar *str);
243 void remove_space (gchar *str);
244 void unfold_line (gchar *str);
245 void subst_char (gchar *str,
248 gboolean is_header_line (const gchar *str);
249 gboolean is_ascii_str (const guchar *str);
250 gint get_quote_level (const gchar *str);
251 gchar *strstr_with_skip_quote (const gchar *haystack,
252 const gchar *needle);
253 gchar **strsplit_with_quote (const gchar *str,
257 GList *uri_list_extract_filenames (const gchar *uri_list);
258 void decode_uri (gchar *decoded_uri,
259 const gchar *encoded_uri);
261 /* return static strings */
262 gchar *get_home_dir (void);
263 gchar *get_rc_dir (void);
264 gchar *get_news_cache_dir (void);
265 gchar *get_imap_cache_dir (void);
266 gchar *get_mbox_cache_dir (void);
267 gchar *get_mime_tmp_dir (void);
268 gchar *get_template_dir (void);
269 gchar *get_tmp_file (void);
270 gchar *get_domain_name (void);
272 /* file / directory handling */
273 off_t get_file_size (const gchar *file);
274 off_t get_left_file_size (FILE *fp);
275 gboolean file_exist (const gchar *file,
276 gboolean allow_fifo);
277 gboolean is_dir_exist (const gchar *dir);
278 gint change_dir (const gchar *dir);
279 gint make_dir_hier (const gchar *dir);
280 gint remove_all_files (const gchar *dir);
281 gint remove_numbered_files (const gchar *dir,
284 gint remove_all_numbered_files (const gchar *dir);
285 gint remove_dir_recursive (const gchar *dir);
286 gint copy_file (const gchar *src,
288 gint move_file (const gchar *src,
290 gint change_file_mode_rw (FILE *fp,
292 FILE *my_tmpfile (void);
294 #define is_file_exist(file) file_exist(file, FALSE)
295 #define is_file_or_fifo_exist(file) file_exist(file, TRUE)
297 /* process execution */
298 gint execute_async (gchar *const argv[]);
299 gint execute_sync (gchar *const argv[]);
300 gint execute_command_line (const gchar *cmdline,
303 /* open URI with external browser */
304 gint open_uri(const gchar *uri, const gchar *cmdline);
307 time_t remote_tzoffset_sec (const gchar *zone);
308 time_t tzoffset_sec (time_t *now);
309 gchar *tzoffset (time_t *now);
310 void get_rfc822_date (gchar *buf,
314 void set_log_file (const gchar *filename);
315 void close_log_file (void);
316 void log_verbosity_set (gboolean verbose);
317 void debug_print_real (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
318 void log_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
319 void log_message (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
320 void log_warning (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
321 void log_error (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
323 /* subject threading */
324 void * subject_table_lookup(GHashTable *subject_table, gchar * subject);
325 void subject_table_insert(GHashTable *subject_table, gchar * subject,
327 void subject_table_remove(GHashTable *subject_table, gchar * subject);
328 gboolean subject_is_reply(const gchar *subject);
331 #endif /* __UTILS_H__ */