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