27#define GEANY_UTILS_H 1
42#ifndef GEANY_DISABLE_DEPRECATED
43#define NZV(ptr) (!EMPTY(ptr))
50#define SETPTR(ptr, result) \
52 gpointer setptr_tmp = ptr;\
57#ifndef GEANY_DISABLE_DEPRECATED
59#define setptr(ptr, result) \
61 gpointer setptr_tmp = ptr;\
72#define utils_strdupa(str) \
73 strcpy(g_alloca(strlen(str) + 1), str)
77#define utils_get_setting(type, home, sys, group, key, default_val)\
78 (g_key_file_has_key(home, group, key, NULL)) ?\
79 utils_get_setting_##type(home, group, key, default_val) :\
80 utils_get_setting_##type(sys, group, key, default_val)
84#define utils_filenamecmp(a, b) utils_str_casecmp((a), (b))
86#define utils_filenamecmp(a, b) strcmp((a), (b))
94#define foreach_c_array(item, array, len) \
95 for (item = array; item < &array[len]; item++)
101#define foreach_array(type, item, array) \
102 foreach_c_array(item, ((type*)(gpointer)array->data), array->len)
108#define foreach_ptr_array(item, idx, ptr_array) \
109 for (idx = 0, item = ((ptr_array)->len > 0 ? g_ptr_array_index((ptr_array), 0) : NULL); \
110 idx < (ptr_array)->len; ++idx, item = g_ptr_array_index((ptr_array), idx))
115#define foreach_list(node, list) \
116 for (node = list; node != NULL; node = node->next)
121#define foreach_slist(node, list) \
122 foreach_list(node, list)
127#define foreach_list_safe(node, list) \
128 for (GList *_node = (list), *_next = (list) ? (list)->next : NULL; \
129 (node = _node) != NULL; \
130 _node = _next, _next = _next ? _next->next : NULL)
137#define foreach_dir(filename, dir)\
138 for ((filename) = g_dir_read_name(dir); (filename) != NULL; (filename) = g_dir_read_name(dir))
145#define foreach_str(char_ptr, string) \
146 for (char_ptr = string; *char_ptr; char_ptr++)
152#define foreach_strv(str_ptr, strv)\
153 if (!(strv)) {} else foreach_str(str_ptr, strv)
159#define foreach_range(i, size) \
160 for (i = 0; i < size; i++)
179gint
utils_mkdir(
const gchar *path, gboolean create_parent_dirs);
181gboolean
utils_get_setting_boolean(GKeyFile *config,
const gchar *section,
const gchar *key,
const gboolean default_value);
185gchar *
utils_get_setting_string(GKeyFile *config,
const gchar *section,
const gchar *key,
const gchar *default_value);
187gboolean
utils_spawn_sync(
const gchar *dir, gchar **argv, gchar **env, GSpawnFlags flags,
188 GSpawnChildSetupFunc child_setup, gpointer user_data, gchar **std_out,
189 gchar **std_err, gint *exit_status, GError **
error);
191gboolean
utils_spawn_async(
const gchar *dir, gchar **argv, gchar **env, GSpawnFlags flags,
192 GSpawnChildSetupFunc child_setup, gpointer user_data, GPid *child_pid,
207gchar **
utils_copy_environment(
const gchar **exclude_vars,
const gchar *first_varname, ...) G_GNUC_NULL_TERMINATED;
226 RESOURCE_DIR_LIBEXEC,
229} GeanyResourceDirType;
260gint
utils_string_find(GString *haystack, gint start, gint end,
const gchar *needle);
265 guint match_num,
const gchar *replace, gboolean literal);
269gint
utils_strpos(
const gchar* haystack,
const gchar *needle);
282 gulong display_unit);
293 GIOFunc func, gpointer data);
301gchar **
utils_strv_new(const gchar *first, ...) G_GNUC_NULL_TERMINATED;
void error(const errorSelection selection, const char *const format,...)
#define G_GNUC_WARN_UNUSED_RESULT
gchar * utils_make_human_readable_str(guint64 size, gulong block_size, gulong display_unit)
gchar * utils_get_path_from_uri(const gchar *uri)
gboolean utils_parse_color(const gchar *spec, GdkColor *color)
GEANY_EXPORT_SYMBOL gchar * utils_strv_find_lcs(gchar **strv, gssize strv_len, const gchar *delim)
GEANY_EXPORT_SYMBOL gchar * utils_strv_find_common_prefix(gchar **strv, gssize strv_len)
gboolean utils_is_short_html_tag(const gchar *tag_name)
gchar * utils_get_help_url(const gchar *suffix)
gboolean utils_str_has_upper(const gchar *str)
gchar * utils_get_os_info_string(void)
gint utils_color_to_bgr(const GdkColor *c)
gchar * utils_parse_and_format_build_date(const gchar *input)
gint utils_strpos(const gchar *haystack, const gchar *needle)
GEANY_EXPORT_SYMBOL gchar ** utils_strv_new(const gchar *first,...)
GSList * utils_get_config_files(const gchar *subdir)
gchar ** utils_strv_join(gchar **first, gchar **second)
const gchar * utils_path_skip_root(const gchar *path)
gchar * utils_get_current_file_dir_utf8(void)
void utils_tidy_path(gchar *filename)
gchar * utils_get_initials(const gchar *name)
gchar * utils_get_current_time_string(gboolean include_microseconds)
gboolean utils_is_absolute_path(const gchar *path)
const gchar * utils_resource_dir(GeanyResourceDirType type)
gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash)
guint utils_string_regex_replace_all(GString *haystack, GRegex *regex, guint match_num, const gchar *replace, gboolean literal)
GIOChannel * utils_set_up_io_channel(gint fd, GIOCondition cond, gboolean nblock, GIOFunc func, gpointer data)
void utils_ensure_same_eol_characters(GString *string, gint target_eol_mode)
gint utils_string_find(GString *haystack, gint start, gint end, const gchar *needle)
gdouble utils_scale_round(gdouble val, gdouble factor)
GDate * utils_parse_date(const gchar *input)
gint utils_string_replace(GString *str, gint pos, gint len, const gchar *replace)
gint utils_get_line_endings(const gchar *buffer, gsize size)
gint utils_parse_color_to_bgr(const gchar *spec)
gboolean utils_wrap_string(gchar *string, gint wrapstart)
gboolean utils_is_uri(const gchar *uri)
void utils_str_replace_all(gchar **haystack, const gchar *needle, const gchar *replacement)
gchar utils_brace_opposite(gchar ch)
const gchar * utils_get_uri_file_prefix(void)
const gchar * utils_get_eol_char(gint eol_mode)
gboolean utils_isbrace(gchar c, gboolean include_angles)
gboolean utils_is_opening_brace(gchar c, gboolean include_angles)
const gchar * utils_get_eol_short_name(gint eol_mode)
void utils_start_new_geany_instance(const gchar *doc_path)
const gchar * utils_get_default_dir_utf8(void)
gboolean utils_is_remote_path(const gchar *path)
gchar * utils_get_user_config_dir(void)
void utils_free_pointers(gsize arg_count,...)
gint utils_is_file_writable(const gchar *locale_filename)
gboolean utils_atob(const gchar *str)
gchar * utils_get_hex_from_color(GdkColor *color)
const gchar * utils_get_eol_name(gint eol_mode)
void utils_open_browser(const gchar *uri)
Tries to open the given URI in a browser.
gchar * utils_str_middle_truncate(const gchar *string, guint truncate_length)
Truncates the input string to a given length.
gboolean utils_spawn_sync(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags flags, GSpawnChildSetupFunc child_setup, gpointer user_data, gchar **std_out, gchar **std_err, gint *exit_status, GError **error)
Wraps spawn_sync(), which see.
gint utils_write_file(const gchar *filename, const gchar *text)
Writes text into a file named filename.
gint utils_str_casecmp(const gchar *s1, const gchar *s2)
A replacement function for g_strncasecmp() to compare strings case-insensitive.
guint utils_string_replace_all(GString *haystack, const gchar *needle, const gchar *replace)
Replaces all occurrences of needle in haystack with replace.
gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gchar *key, const gint default_value)
Wraps g_key_file_get_integer() to add a default value argument.
gboolean utils_get_setting_boolean(GKeyFile *config, const gchar *section, const gchar *key, const gboolean default_value)
Wraps g_key_file_get_boolean() to add a default value argument.
gchar * utils_get_utf8_from_locale(const gchar *locale_text)
Converts the given string (in locale encoding) into UTF-8 encoding.
GSList * utils_get_file_list(const gchar *path, guint *length, GError **error)
Gets a sorted list of files from the specified directory.
GSList * utils_get_file_list_full(const gchar *path, gboolean full_path, gboolean sort, GError **error)
Gets a list of files from the specified directory.
gchar * utils_get_date_time(const gchar *format, time_t *time_to_use)
Retrieves a formatted date/time string from strftime().
gchar * utils_find_open_xml_tag(const gchar sel[], gint size)
Searches backward through size bytes looking for a '<'.
const gchar * utils_find_open_xml_tag_pos(const gchar sel[], gint size)
Searches backward through size bytes looking for a '<'.
gchar ** utils_copy_environment(const gchar **exclude_vars, const gchar *first_varname,...) G_GNUC_NULL_TERMINATED
Copies the current environment into a new array.
gint utils_mkdir(const gchar *path, gboolean create_parent_dirs)
Creates a directory if it doesn't already exist.
gchar * utils_str_remove_chars(gchar *string, const gchar *chars)
Removes characters from a string, in place.
gboolean utils_str_equal(const gchar *a, const gchar *b)
NULL-safe string comparison.
gchar ** utils_strv_shorten_file_list(gchar **file_names, gssize file_names_len)
Transform file names in a list to be shorter.
gchar * utils_remove_ext_from_filename(const gchar *filename)
Removes the extension from filename and return the result in a newly allocated string.
gchar * utils_get_setting_string(GKeyFile *config, const gchar *section, const gchar *key, const gchar *default_value)
Wraps g_key_file_get_string() to add a default value argument.
gchar * utils_get_real_path(const gchar *file_name)
Get a link-dereferenced, absolute version of a file name.
gchar * utils_get_locale_from_utf8(const gchar *utf8_text)
Converts the given UTF-8 encoded string into locale encoding.
gboolean utils_spawn_async(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags flags, GSpawnChildSetupFunc child_setup, gpointer user_data, GPid *child_pid, GError **error)
Wraps spawn_async(), which see.
guint utils_string_replace_first(GString *haystack, const gchar *needle, const gchar *replace)
Replaces only the first occurrence of needle in haystack with replace.