2000-04-26 04:03:38 -04:00
|
|
|
#ifndef __MISC_H
|
|
|
|
#define __MISC_H
|
|
|
|
|
2008-04-25 04:42:47 -04:00
|
|
|
int g_input_add_poll(int fd, int priority, int condition,
|
|
|
|
GInputFunction function, void *data);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
/* `str' should be type char[MAX_INT_STRLEN] */
|
|
|
|
#define ltoa(str, num) \
|
|
|
|
g_snprintf(str, sizeof(str), "%d", num)
|
|
|
|
|
|
|
|
typedef void* (*FOREACH_FIND_FUNC) (void *item, void *data);
|
2001-01-28 10:43:38 -05:00
|
|
|
typedef int (*COLUMN_LEN_FUNC)(void *data);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-05-17 12:50:52 -04:00
|
|
|
/* Returns 1 if tv1 > tv2, -1 if tv2 > tv1 or 0 if they're equal. */
|
2000-11-30 18:12:42 -05:00
|
|
|
int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2);
|
2001-05-17 12:50:52 -04:00
|
|
|
/* Returns "tv1 - tv2", returns the result in milliseconds. Note that
|
|
|
|
if the difference is too large, the result might be invalid. */
|
2000-04-26 04:03:38 -04:00
|
|
|
long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2);
|
|
|
|
|
|
|
|
GSList *gslist_find_string(GSList *list, const char *key);
|
|
|
|
GSList *gslist_find_icase_string(GSList *list, const char *key);
|
|
|
|
GList *glist_find_string(GList *list, const char *key);
|
|
|
|
GList *glist_find_icase_string(GList *list, const char *key);
|
2015-02-11 18:07:22 -05:00
|
|
|
GSList *gslist_remove_string (GSList *list, const char *str);
|
|
|
|
|
|
|
|
void gslist_free_full (GSList *list, GDestroyNotify free_func);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
void *gslist_foreach_find(GSList *list, FOREACH_FIND_FUNC func, const void *data);
|
2000-06-17 21:18:12 -04:00
|
|
|
|
|
|
|
/* `list' contains pointer to structure with a char* to string. */
|
|
|
|
char *gslistptr_to_string(GSList *list, int offset, const char *delimiter);
|
|
|
|
/* `list' contains char* */
|
|
|
|
char *gslist_to_string(GSList *list, const char *delimiter);
|
|
|
|
|
|
|
|
/* save all keys in hash table to linked list - you shouldn't remove any
|
|
|
|
items while using this list, use g_slist_free() after you're done with it */
|
|
|
|
GSList *hashtable_get_keys(GHashTable *hash);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
/* easy way to check if regexp matches */
|
|
|
|
int regexp_match(const char *str, const char *regexp);
|
|
|
|
|
2000-08-12 11:50:50 -04:00
|
|
|
/* Create the directory and all it's parent directories */
|
|
|
|
int mkpath(const char *path, int mode);
|
|
|
|
/* convert ~/ to $HOME */
|
2000-04-26 04:03:38 -04:00
|
|
|
char *convert_home(const char *path);
|
|
|
|
|
|
|
|
/* Case-insensitive string hash functions */
|
|
|
|
int g_istr_equal(gconstpointer v, gconstpointer v2);
|
|
|
|
unsigned int g_istr_hash(gconstpointer v);
|
|
|
|
|
2000-06-17 09:16:42 -04:00
|
|
|
/* Case-insensitive GCompareFunc func */
|
|
|
|
int g_istr_cmp(gconstpointer v, gconstpointer v2);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
/* Find `mask' from `data', you can use * and ? wildcards. */
|
|
|
|
int match_wildcards(const char *mask, const char *data);
|
|
|
|
|
|
|
|
/* octal <-> decimal conversions */
|
|
|
|
int octal2dec(int octal);
|
|
|
|
int dec2octal(int decimal);
|
|
|
|
|
2001-01-14 13:16:39 -05:00
|
|
|
/* Get time in human readable form with localtime() + asctime() */
|
|
|
|
char *my_asctime(time_t t);
|
|
|
|
|
2001-01-28 10:43:38 -05:00
|
|
|
/* Returns number of columns needed to print items.
|
|
|
|
save_column_widths is filled with length of each column. */
|
|
|
|
int get_max_column_count(GSList *items, COLUMN_LEN_FUNC len_func,
|
2001-02-09 23:54:09 -05:00
|
|
|
int max_width, int max_columns,
|
|
|
|
int item_extra, int item_min_size,
|
2001-01-28 10:43:38 -05:00
|
|
|
int **save_column_widths, int *rows);
|
|
|
|
|
|
|
|
/* Return a column sorted copy of a list. */
|
|
|
|
GSList *columns_sort_list(GSList *list, int rows);
|
|
|
|
|
2001-08-08 16:00:25 -04:00
|
|
|
/* Expand escape string, the first character in data should be the
|
|
|
|
one after '\'. Returns the expanded character or -1 if error. */
|
|
|
|
int expand_escape(const char **data);
|
|
|
|
|
2002-12-28 09:59:29 -05:00
|
|
|
int nearest_power(int num);
|
|
|
|
|
2002-12-28 12:54:13 -05:00
|
|
|
/* Returns TRUE / FALSE */
|
|
|
|
int parse_time_interval(const char *time, int *msecs);
|
|
|
|
int parse_size(const char *size, int *bytes);
|
|
|
|
|
2008-03-03 07:33:17 -05:00
|
|
|
/* Return TRUE if all characters in `str' are numbers.
|
|
|
|
Stop when `end_char' is found from string. */
|
|
|
|
int is_numeric(const char *str, char end_char);
|
|
|
|
|
|
|
|
/* Like strlcpy(), but return -1 if buffer was overflown, 0 if not. */
|
|
|
|
int strocpy(char *dest, const char *src, size_t dstsize);
|
|
|
|
|
|
|
|
/* strstr() with case-ignoring */
|
|
|
|
char *stristr(const char *data, const char *key);
|
|
|
|
|
2008-03-28 08:59:26 -04:00
|
|
|
/* like strstr(), but matches only for full words. */
|
2008-03-03 07:33:17 -05:00
|
|
|
char *strstr_full(const char *data, const char *key);
|
|
|
|
char *stristr_full(const char *data, const char *key);
|
|
|
|
|
2010-04-03 16:09:37 -04:00
|
|
|
char *ascii_strup(char *str);
|
|
|
|
char *ascii_strdown(char *str);
|
|
|
|
|
2008-03-03 07:33:17 -05:00
|
|
|
/* Escape all '"', "'" and '\' chars with '\' */
|
|
|
|
char *escape_string(const char *str);
|
|
|
|
|
|
|
|
/* convert all low-ascii (<32) to ^<A..> combinations */
|
|
|
|
char *show_lowascii(const char *str);
|
|
|
|
|
|
|
|
/* replace all `from' chars in string to `to' chars. returns `str' */
|
|
|
|
char *replace_chars(char *str, char from, char to);
|
|
|
|
|
|
|
|
/* return how many items `array' has */
|
|
|
|
int strarray_length(char **array);
|
|
|
|
/* return index of `item' in `array' or -1 if not found */
|
|
|
|
int strarray_find(char **array, const char *item);
|
|
|
|
|
|
|
|
/* string -> uoff_t */
|
|
|
|
uoff_t str_to_uofft(const char *str);
|
|
|
|
|
|
|
|
/* find `item' from a space separated `list' */
|
|
|
|
int find_substr(const char *list, const char *item);
|
|
|
|
|
2014-06-13 00:39:02 -04:00
|
|
|
/* split `str' into `len' sized substrings */
|
2014-10-11 12:47:39 -04:00
|
|
|
char **strsplit_len(const char *str, int len, gboolean onspace);
|
2014-06-13 00:39:02 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
#endif
|