Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / core / misc.h
1 #ifndef __MISC_H
2 #define __MISC_H
3
4 int g_input_add_poll(int fd, int priority, int condition,
5                      GInputFunction function, void *data);
6
7 /* `str' should be type char[MAX_INT_STRLEN] */
8 #define ltoa(str, num) \
9         g_snprintf(str, sizeof(str), "%d", num)
10
11 typedef void* (*FOREACH_FIND_FUNC) (void *item, void *data);
12 typedef int (*COLUMN_LEN_FUNC)(void *data);
13
14 /* Returns 1 if tv1 > tv2, -1 if tv2 > tv1 or 0 if they're equal. */
15 int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2);
16 /* Returns "tv1 - tv2", returns the result in milliseconds. Note that
17    if the difference is too large, the result might be invalid. */
18 long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2);
19
20 GSList *gslist_find_string(GSList *list, const char *key);
21 GSList *gslist_find_icase_string(GSList *list, const char *key);
22 GList *glist_find_string(GList *list, const char *key);
23 GList *glist_find_icase_string(GList *list, const char *key);
24
25 void *gslist_foreach_find(GSList *list, FOREACH_FIND_FUNC func, const void *data);
26
27 /* `list' contains pointer to structure with a char* to string. */
28 char *gslistptr_to_string(GSList *list, int offset, const char *delimiter);
29 /* `list' contains char* */
30 char *gslist_to_string(GSList *list, const char *delimiter);
31
32 /* save all keys in hash table to linked list - you shouldn't remove any
33    items while using this list, use g_slist_free() after you're done with it */
34 GSList *hashtable_get_keys(GHashTable *hash);
35
36 /* easy way to check if regexp matches */
37 int regexp_match(const char *str, const char *regexp);
38
39 /* Create the directory and all it's parent directories */
40 int mkpath(const char *path, int mode);
41 /* convert ~/ to $HOME */
42 char *convert_home(const char *path);
43
44 /* Case-insensitive string hash functions */
45 int g_istr_equal(gconstpointer v, gconstpointer v2);
46 unsigned int g_istr_hash(gconstpointer v);
47
48 /* Case-insensitive GCompareFunc func */
49 int g_istr_cmp(gconstpointer v, gconstpointer v2);
50
51 /* Find `mask' from `data', you can use * and ? wildcards. */
52 int match_wildcards(const char *mask, const char *data);
53
54 /* octal <-> decimal conversions */
55 int octal2dec(int octal);
56 int dec2octal(int decimal);
57
58 /* Get time in human readable form with localtime() + asctime() */
59 char *my_asctime(time_t t);
60
61 /* Returns number of columns needed to print items.
62    save_column_widths is filled with length of each column. */
63 int get_max_column_count(GSList *items, COLUMN_LEN_FUNC len_func,
64                          int max_width, int max_columns,
65                          int item_extra, int item_min_size,
66                          int **save_column_widths, int *rows);
67
68 /* Return a column sorted copy of a list. */
69 GSList *columns_sort_list(GSList *list, int rows);
70
71 /* Expand escape string, the first character in data should be the
72    one after '\'. Returns the expanded character or -1 if error. */
73 int expand_escape(const char **data);
74
75 int nearest_power(int num);
76
77 /* Returns TRUE / FALSE */
78 int parse_time_interval(const char *time, int *msecs);
79 int parse_size(const char *size, int *bytes);
80
81 /* Return TRUE if all characters in `str' are numbers.
82    Stop when `end_char' is found from string. */
83 int is_numeric(const char *str, char end_char);
84
85 /* Like strlcpy(), but return -1 if buffer was overflown, 0 if not. */
86 int strocpy(char *dest, const char *src, size_t dstsize);
87
88 /* strstr() with case-ignoring */
89 char *stristr(const char *data, const char *key);
90
91 /* like strstr(), but matches only for full words. */
92 char *strstr_full(const char *data, const char *key);
93 char *stristr_full(const char *data, const char *key);
94
95 char *ascii_strup(char *str);
96 char *ascii_strdown(char *str);
97
98 /* Escape all '"', "'" and '\' chars with '\' */
99 char *escape_string(const char *str);
100
101 /* convert all low-ascii (<32) to ^<A..> combinations */
102 char *show_lowascii(const char *str);
103
104 /* replace all `from' chars in string to `to' chars. returns `str' */
105 char *replace_chars(char *str, char from, char to);
106
107 /* return how many items `array' has */
108 int strarray_length(char **array);
109 /* return index of `item' in `array' or -1 if not found */
110 int strarray_find(char **array, const char *item);
111
112 /* string -> uoff_t */
113 uoff_t str_to_uofft(const char *str);
114
115 /* find `item' from a space separated `list' */
116 int find_substr(const char *list, const char *item);
117
118 #endif