geany
1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
![]() ![]() |
#include "utils.h"
#include "app.h"
#include "dialogs.h"
#include "document.h"
#include "prefs.h"
#include "prefix.h"
#include "sciwrappers.h"
#include "spawn.h"
#include "support.h"
#include "tm_source_file.h"
#include "templates.h"
#include "ui_utils.h"
#include "win32.h"
#include "osx.h"
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
Go to the source code of this file.
Functions | |
void | utils_open_browser (const gchar *uri) |
Tries to open the given URI in a browser. More... | |
gint | utils_get_line_endings (const gchar *buffer, gsize size) |
gboolean | utils_isbrace (gchar c, gboolean include_angles) |
gboolean | utils_is_opening_brace (gchar c, gboolean include_angles) |
gint | utils_write_file (const gchar *filename, const gchar *text) |
Writes text into a file named filename. More... | |
gchar * | utils_find_open_xml_tag (const gchar sel[], gint size) |
Searches backward through size bytes looking for a '<'. More... | |
const gchar * | utils_find_open_xml_tag_pos (const gchar sel[], gint size) |
Searches backward through size bytes looking for a '<'. More... | |
gboolean | utils_is_short_html_tag (const gchar *tag_name) |
const gchar * | utils_get_eol_name (gint eol_mode) |
const gchar * | utils_get_eol_short_name (gint eol_mode) |
const gchar * | utils_get_eol_char (gint eol_mode) |
void | utils_ensure_same_eol_characters (GString *string, gint target_eol_mode) |
gboolean | utils_atob (const gchar *str) |
gboolean | utils_is_absolute_path (const gchar *path) |
const gchar * | utils_path_skip_root (const gchar *path) |
gdouble | utils_scale_round (gdouble val, gdouble factor) |
static gchar * | utf8_strdown (const gchar *str) |
gint | utils_str_casecmp (const gchar *s1, const gchar *s2) |
A replacement function for g_strncasecmp() to compare strings case-insensitive. More... | |
gchar * | utils_str_middle_truncate (const gchar *string, guint truncate_length) |
Truncates the input string to a given length. More... | |
gboolean | utils_str_equal (const gchar *a, const gchar *b) |
NULL-safe string comparison. More... | |
gchar * | utils_remove_ext_from_filename (const gchar *filename) |
Removes the extension from filename and return the result in a newly allocated string. More... | |
gchar | utils_brace_opposite (gchar ch) |
gint | utils_is_file_writable (const gchar *locale_filename) |
void | utils_str_replace_all (gchar **haystack, const gchar *needle, const gchar *replacement) |
gint | utils_strpos (const gchar *haystack, const gchar *needle) |
gchar * | utils_get_date_time (const gchar *format, time_t *time_to_use) |
Retrieves a formatted date/time string from strftime(). More... | |
gchar * | utils_get_initials (const gchar *name) |
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. More... | |
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. More... | |
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. More... | |
gchar * | utils_get_hex_from_color (GdkColor *color) |
gchar * | utils_get_current_file_dir_utf8 (void) |
void | utils_beep (void) |
gchar * | utils_make_human_readable_str (guint64 size, gulong block_size, gulong display_unit) |
gboolean | utils_parse_color (const gchar *spec, GdkColor *color) |
gint | utils_color_to_bgr (const GdkColor *c) |
gint | utils_parse_color_to_bgr (const gchar *spec) |
gchar * | utils_get_current_time_string (gboolean include_microseconds) |
GIOChannel * | utils_set_up_io_channel (gint fd, GIOCondition cond, gboolean nblock, GIOFunc func, gpointer data) |
gboolean | utils_str_replace_escape (gchar *string, gboolean keep_backslash) |
gboolean | utils_wrap_string (gchar *string, gint wrapstart) |
gchar * | utils_get_locale_from_utf8 (const gchar *utf8_text) |
Converts the given UTF-8 encoded string into locale encoding. More... | |
gchar * | utils_get_utf8_from_locale (const gchar *locale_text) |
Converts the given string (in locale encoding) into UTF-8 encoding. More... | |
void | utils_free_pointers (gsize arg_count,...) |
GEANY_EXPORT_SYMBOL gchar ** | utils_strv_new (const gchar *first,...) |
gint | utils_mkdir (const gchar *path, gboolean create_parent_dirs) |
Creates a directory if it doesn't already exist. More... | |
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. More... | |
GSList * | utils_get_file_list (const gchar *path, guint *length, GError **error) |
Gets a sorted list of files from the specified directory. More... | |
gboolean | utils_str_has_upper (const gchar *str) |
gint | utils_string_find (GString *haystack, gint start, gint end, const gchar *needle) |
gint | utils_string_replace (GString *str, gint pos, gint len, const gchar *replace) |
guint | utils_string_replace_all (GString *haystack, const gchar *needle, const gchar *replace) |
Replaces all occurrences of needle in haystack with replace. More... | |
guint | utils_string_replace_first (GString *haystack, const gchar *needle, const gchar *replace) |
Replaces only the first occurrence of needle in haystack with replace. More... | |
guint | utils_string_regex_replace_all (GString *haystack, GRegex *regex, guint match_num, const gchar *replace, gboolean literal) |
const gchar * | utils_get_default_dir_utf8 (void) |
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. More... | |
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. More... | |
const gchar * | utils_get_uri_file_prefix (void) |
gchar * | utils_get_path_from_uri (const gchar *uri) |
gboolean | utils_is_uri (const gchar *uri) |
gboolean | utils_is_remote_path (const gchar *path) |
void | utils_tidy_path (gchar *filename) |
gchar * | utils_str_remove_chars (gchar *string, const gchar *chars) |
Removes characters from a string, in place. More... | |
GSList * | utils_get_config_files (const gchar *subdir) |
gchar * | utils_get_help_url (const gchar *suffix) |
static gboolean | str_in_array (const gchar **haystack, const gchar *needle) |
gchar ** | utils_copy_environment (const gchar **exclude_vars, const gchar *first_varname,...) |
Copies the current environment into a new array. More... | |
gchar ** | utils_strv_join (gchar **first, gchar **second) |
GEANY_EXPORT_SYMBOL gchar * | utils_strv_find_common_prefix (gchar **strv, gssize strv_len) |
GEANY_EXPORT_SYMBOL gchar * | utils_strv_find_lcs (gchar **strv, gssize strv_len, const gchar *delim) |
gchar ** | utils_strv_shorten_file_list (gchar **file_names, gssize file_names_len) |
Transform file names in a list to be shorter. More... | |
GDate * | utils_parse_date (const gchar *input) |
gchar * | utils_parse_and_format_build_date (const gchar *input) |
gchar * | utils_get_user_config_dir (void) |
static gboolean | is_osx_bundle (void) |
const gchar * | utils_resource_dir (GeanyResourceDirType type) |
void | utils_start_new_geany_instance (const gchar *doc_path) |
gchar * | utils_get_real_path (const gchar *file_name) |
Get a link-dereferenced, absolute version of a file name. More... | |
gchar * | utils_get_os_info_string (void) |
|
static |
Definition at line 2287 of file utils.c.
Referenced by utils_resource_dir(), and utils_start_new_geany_instance().
|
static |
Definition at line 1928 of file utils.c.
References NULL, and utils_str_equal().
Referenced by utils_copy_environment().
|
static |
Definition at line 471 of file utils.c.
Referenced by utils_str_casecmp().
gboolean utils_atob | ( | const gchar * | str | ) |
void utils_beep | ( | void | ) |
Definition at line 918 of file utils.c.
References GeanyPrefs::beep_on_errors, and prefs.
Referenced by build_exit_cb(), check_current_word(), configure_plugins(), document_find_text(), document_replace_sel(), document_replace_text(), document_save_file(), document_search_bar_find(), editor_start_auto_complete(), encodings_radio_item_change_cb(), focus_msgwindow(), goto_tag(), insert_date(), insert_multiline_comment(), join_paragraph(), msgwin_goto_messages_file_line(), notebook_switch_tablastused(), on_editor_notify(), on_find_dialog_response(), on_find_entry_activate_backward(), on_find_previous1_activate(), on_go_to_line_activate(), on_menu_write_unicode_bom1_toggled(), on_replace_dialog_response(), on_snippet_keybinding_activate(), on_toolbutton_goto_entry_activate(), reflow_paragraph(), replace_in_session(), save_as_dialog_handle_response(), search_find_selection(), search_find_usage(), search_finished(), and symbols_goto_tag().
gchar utils_brace_opposite | ( | gchar | ch | ) |
Definition at line 638 of file utils.c.
Referenced by brace_match().
gint utils_color_to_bgr | ( | const GdkColor * | c | ) |
gchar ** utils_copy_environment | ( | const gchar ** | exclude_vars, |
const gchar * | first_varname, | ||
... | |||
) |
Copies the current environment into a new array.
exclude_vars is a NULL-terminated
array of variable names which should be not copied. All further arguments are key, value pairs of variables which should be added to the environment.
The argument list must be NULL-terminated
.
exclude_vars | NULL-terminated array of variable names to exclude. |
first_varname | Name of the first variable to copy into the new array. |
... | Key-value pairs of variable names and values, NULL-terminated . |
g_strfreev()
to free it. Definition at line 1956 of file utils.c.
References NULL, and str_in_array().
Referenced by run_command().
void utils_ensure_same_eol_characters | ( | GString * | string, |
gint | target_eol_mode | ||
) |
Definition at line 405 of file utils.c.
References SC_EOL_LF, utils_get_eol_char(), and utils_string_replace_all().
Referenced by convert_eol_characters(), document_new_file(), and read_file().
gchar * utils_find_open_xml_tag | ( | const gchar | sel[], |
gint | size | ||
) |
Searches backward through size bytes looking for a '<'.
sel | . |
size | . |
NULL
if no opening tag was found. Definition at line 269 of file utils.c.
References NULL, and utils_find_open_xml_tag_pos().
Referenced by get_xml_indent(), and handle_xml().
const gchar * utils_find_open_xml_tag_pos | ( | const gchar | sel[], |
gint | size | ||
) |
Searches backward through size bytes looking for a '<'.
sel | . |
size | . |
NULL
if no opening tag was found. Definition at line 294 of file utils.c.
References NULL.
Referenced by utils_find_open_xml_tag().
void utils_free_pointers | ( | gsize | arg_count, |
... | |||
) |
Definition at line 1293 of file utils.c.
References ptr.
Referenced by get_template_from_file(), make_comment_block(), on_config_file_clicked(), prepare_run_cmd(), search_find_in_files(), templates_replace_default_dates(), and update_config().
GSList * utils_get_config_files | ( | const gchar * | subdir | ) |
Definition at line 1867 of file utils.c.
References app, GeanyApp::configdir, GeanyApp::datadir, foreach_slist, list, NULL, SETPTR, utils_get_file_list_full(), utils_mkdir(), utils_str_casecmp(), and utils_str_equal().
Referenced by add_color_scheme_items(), and populate_file_template_menu().
gchar * utils_get_current_file_dir_utf8 | ( | void | ) |
Definition at line 897 of file utils.c.
References document_get_current(), GeanyDocument::file_name, and NULL.
Referenced by dialogs_show_open_file(), goto_compiler_file_line(), on_menu_open_selected_file1_activate(), and search_show_find_in_files_dialog_full().
gchar * utils_get_current_time_string | ( | gboolean | include_microseconds | ) |
Definition at line 1019 of file utils.c.
References format.
Referenced by handler_log(), and msgwin_status_add_string().
gchar * utils_get_date_time | ( | const gchar * | format, |
time_t * | time_to_use | ||
) |
Retrieves a formatted date/time string from strftime().
This function should be preferred to directly calling strftime() since this function works on UTF-8 encoded strings.
format | The format string to pass to strftime(3). See the strftime(3) documentation for details, in UTF-8 encoding. |
time_to_use | The date/time to use, in time_t format or NULL to use the current time. |
Definition at line 736 of file utils.c.
Referenced by add_page_header(), backupcopy_document_save_cb(), get_date(), insert_date(), and templates_replace_default_dates().
const gchar * utils_get_default_dir_utf8 | ( | void | ) |
Definition at line 1615 of file utils.c.
References app, GeanyProject::base_path, GeanyPrefs::default_open_path, EMPTY, NULL, prefs, and GeanyApp::project.
Referenced by create_save_file_dialog(), dialogs_show_open_file(), and search_show_find_in_files_dialog_full().
const gchar * utils_get_eol_char | ( | gint | eol_mode | ) |
Definition at line 393 of file utils.c.
References SC_EOL_CR, and SC_EOL_CRLF.
Referenced by document_open_file_list(), editor_get_eol_char(), make_comment_block(), and utils_ensure_same_eol_characters().
const gchar * utils_get_eol_name | ( | gint | eol_mode | ) |
Definition at line 371 of file utils.c.
References _, SC_EOL_CR, and SC_EOL_CRLF.
Referenced by editor_get_eol_char_name(), and prefs_show_dialog().
const gchar * utils_get_eol_short_name | ( | gint | eol_mode | ) |
Definition at line 382 of file utils.c.
References _, SC_EOL_CR, and SC_EOL_CRLF.
Referenced by create_statusbar_statistics().
GSList * utils_get_file_list | ( | const gchar * | path, |
guint * | length, | ||
GError ** | error | ||
) |
Gets a sorted list of files from the specified directory.
Locale encoding is expected for path and used for the file list. The list and the data in the list should be freed after use, e.g.:
path | The path of the directory to scan, in locale encoding. |
length | The location to store the number of non-NULL data items in the list, unless NULL . |
error | The location for storing a possible error, or NULL . |
NULL
if no files were found. The list and its data should be freed when no longer needed. Definition at line 1441 of file utils.c.
References error(), list, and utils_get_file_list_full().
Referenced by load_plugins_from_path(), refresh(), and search_get_argv().
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.
Locale encoding is expected for path and used for the file list. The list and the data in the list should be freed after use, e.g.:
path | The path of the directory to scan, in locale encoding. |
full_path | Whether to include the full path for each filename in the list. Obviously this will use more memory. |
sort | Whether to sort alphabetically (UTF-8 safe). |
error | The location for storing a possible error, or NULL . |
NULL
if no files were found. The list and its data should be freed when no longer needed. Definition at line 1396 of file utils.c.
References error(), filename, foreach_dir, list, NULL, and utils_str_casecmp().
Referenced by init_user_tags(), utils_get_config_files(), and utils_get_file_list().
gchar * utils_get_help_url | ( | const gchar * | suffix | ) |
Definition at line 1902 of file utils.c.
References app, GeanyApp::docdir, GEANY_HOMEPAGE, NULL, SETPTR, and utils_get_uri_file_prefix().
Referenced by on_help1_activate(), and open_preferences_help().
gchar * utils_get_hex_from_color | ( | GdkColor * | color | ) |
Definition at line 883 of file utils.c.
References color, NULL, and utils_scale_round().
Referenced by on_color_button_choose_cb(), on_color_dialog_response(), and save_dialog_prefs().
gchar * utils_get_initials | ( | const gchar * | name | ) |
gint utils_get_line_endings | ( | const gchar * | buffer, |
gsize | size | ||
) |
Definition at line 102 of file utils.c.
References SC_EOL_CR, SC_EOL_CRLF, and SC_EOL_LF.
Referenced by document_open_file_full(), document_open_file_list(), and make_comment_block().
gchar * utils_get_locale_from_utf8 | ( | const gchar * | utf8_text | ) |
Converts the given UTF-8 encoded string into locale encoding.
On Windows platforms, it does nothing and instead it just returns a copy of the input string.
utf8_text | UTF-8 encoded text. |
NULL
, NULL
is returned. Definition at line 1243 of file utils.c.
References NULL.
Referenced by backupcopy_document_save_cb(), build_run_cmd(), build_spawn_cmd(), cb_func_file_action(), create_file_save_as_dialog(), create_save_file_dialog(), detect_filetype_conf_file(), dialogs_show_file_properties(), dialogs_show_open_file(), document_activate_cb(), document_check_disk_status(), document_open_file_full(), document_rename_file(), document_save_file(), document_update_tags(), filetypes_detect_from_file(), get_custom_plugin_path(), get_default_dir(), get_real_path_from_utf8(), get_session_file_string(), get_tree_path_filename(), goto_compiler_file_line(), load_session_project_file(), monitor_file_setup(), msgwin_parse_generic_line(), on_color_scheme_changed(), on_current_path(), on_menu_open_selected_file1_activate(), on_new_with_file_template(), on_open_in_new_window_activate(), on_path_entry_activate(), open_external(), open_session_file(), prepare_run_cmd(), project_open(), project_open_cb(), recent_file_activate_cb(), recent_project_activate_cb(), run_dialog(), run_file_chooser(), search_find_in_files(), setup_paths(), show_save_as_gtk(), store_target_directory(), target_directory_button_clicked_cb(), update_config(), and write_config().
gchar * utils_get_os_info_string | ( | void | ) |
gchar * utils_get_path_from_uri | ( | const gchar * | uri | ) |
Definition at line 1704 of file utils.c.
References geany_debug(), NULL, and utils_is_uri().
Referenced by document_open_file_list(), main_handle_filename(), and main_load_project_from_command_line().
gchar * utils_get_real_path | ( | const gchar * | file_name | ) |
Get a link-dereferenced, absolute version of a file name.
This is similar to the POSIX realpath
function when passed a NULL
argument.
realpath()
, namely that it's impossible to determine a suitable size for the returned buffer, and so it's limited to a maximum of PATH_MAX
.file_name | The file name to get the real path of. |
g_free()
when no longer needed, or NULL
if the real path cannot be obtained.Definition at line 2406 of file utils.c.
References tm_get_real_path().
Referenced by document_open_file_full(), get_real_path_from_utf8(), save_doc(), and setup_config_dir().
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.
config | A GKeyFile object. |
section | The group name to look in for the key. |
key | The key to find. |
default_value | The default value which will be returned when section or key don't exist. |
Definition at line 836 of file utils.c.
Referenced by handle_boolean_setting(), init_configuration(), load_dialog_prefs(), load_settings(), load_ui_prefs(), and plugin_init().
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.
config | A GKeyFile object. |
section | The group name to look in for the key. |
key | The key to find. |
default_value | The default value which will be returned when section or key don't exist. |
Definition at line 805 of file utils.c.
Referenced by configuration_load_session_files(), handle_integer_setting(), load_config(), load_dialog_prefs(), load_ui_prefs(), and plugin_init().
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.
config | A GKeyFile object. |
section | The group name to look in for the key. |
key | The key to find. |
default_value | The default value which will be returned when section or key don't exist. |
Definition at line 867 of file utils.c.
References NULL.
Referenced by configuration_load_session_files(), handle_string_setting(), load_config(), load_dialog_prefs(), load_settings(), load_ui_prefs(), plugin_init(), project_load_prefs(), and snippets_load().
const gchar * utils_get_uri_file_prefix | ( | void | ) |
Definition at line 1689 of file utils.c.
Referenced by on_build_menu_item(), and utils_get_help_url().
gchar * utils_get_user_config_dir | ( | void | ) |
Definition at line 2277 of file utils.c.
References NULL.
Referenced by parse_command_line_options().
gchar * utils_get_utf8_from_locale | ( | const gchar * | locale_text | ) |
Converts the given string (in locale encoding) into UTF-8 encoding.
On Windows platforms, it does nothing and instead it just returns a copy of the input string.
locale_text | Text in locale encoding. |
NULL
, NULL
is returned. Definition at line 1272 of file utils.c.
References NULL.
Referenced by add_color_scheme_file(), add_file_item(), add_item(), add_top_level_entry(), build_run_cmd(), document_open_file_full(), get_mtime(), goto_compiler_file_line(), init_user_tags(), load_config(), main_handle_filename(), main_lib(), msgwin_compiler_add_string(), msgwin_msg_add_string(), msgwin_parse_compiler_error_line(), on_color_scheme_changed(), on_config_file_clicked(), on_file_save_dialog_response(), on_find_in_files(), on_menu_open_selected_file1_activate(), on_new_with_file_template(), project_load_file(), read_file(), refresh(), run_dialog(), run_file_chooser(), run_open_dialog(), save_as_dialog_handle_response(), symbols_generate_global_tags(), symbols_show_load_tags_dialog(), target_directory_button_clicked_cb(), and write_data().
gboolean utils_is_absolute_path | ( | const gchar * | path | ) |
gint utils_is_file_writable | ( | const gchar * | locale_filename | ) |
Definition at line 657 of file utils.c.
Referenced by create_config_dir(), and update_config().
gboolean utils_is_opening_brace | ( | gchar | c, |
gboolean | include_angles | ||
) |
Definition at line 178 of file utils.c.
Referenced by brace_match(), and find_previous_brace().
gboolean utils_is_remote_path | ( | const gchar * | path | ) |
Definition at line 1741 of file utils.c.
References NULL, and utils_is_uri().
Referenced by document_open_file_full(), and save_doc().
gboolean utils_is_short_html_tag | ( | const gchar * | tag_name | ) |
Definition at line 338 of file utils.c.
Referenced by get_xml_indent(), and handle_xml().
gboolean utils_is_uri | ( | const gchar * | uri | ) |
Definition at line 1732 of file utils.c.
References NULL, and strstr().
Referenced by main_get_argv_filename(), utils_get_path_from_uri(), and utils_is_remote_path().
gboolean utils_isbrace | ( | gchar | c, |
gboolean | include_angles | ||
) |
Definition at line 159 of file utils.c.
Referenced by auto_close_chars(), delay_match_brace(), editor_highlight_braces(), and goto_matching_brace().
gchar * utils_make_human_readable_str | ( | guint64 | size, |
gulong | block_size, | ||
gulong | display_unit | ||
) |
Definition at line 926 of file utils.c.
Referenced by dialogs_show_file_properties().
gint utils_mkdir | ( | const gchar * | path, |
gboolean | create_parent_dirs | ||
) |
Creates a directory if it doesn't already exist.
Creates intermediate parent directories as needed, too. The permissions of the created directory are set 0700.
path | The path of the directory to create, in locale encoding. |
create_parent_dirs | Whether to create intermediate parent directories if necessary. |
errno
of the failed operation is returned. Definition at line 1359 of file utils.c.
Referenced by backupcopy_create_dir_parts(), configure_response_cb(), create_config_dir(), init_user_tags(), save_settings(), set_status(), update_config(), and utils_get_config_files().
void utils_open_browser | ( | const gchar * | uri | ) |
Tries to open the given URI in a browser.
On Windows, the system's default browser is opened. On non-Windows systems, the browser command set in the preferences dialog is used. In case that fails or it is unset, the user is asked to correct or fill it.
uri | The URI to open in the web browser. |
Definition at line 75 of file utils.c.
References _, GeanyToolPrefs::browser_cmd, dialogs_show_input(), main_widgets, NULL, SETPTR, spawn_async(), tool_prefs, and GeanyMainWidgets::window.
Referenced by homepage_clicked(), on_build_menu_item(), on_help1_activate(), on_help_menu_item_bug_report_activate(), on_help_menu_item_donate_activate(), on_help_menu_item_wiki_activate(), on_website1_activate(), and open_preferences_help().
gchar * utils_parse_and_format_build_date | ( | const gchar * | input | ) |
Definition at line 2261 of file utils.c.
References NULL, and utils_parse_date().
Referenced by create_dialog(), and parse_command_line_options().
gboolean utils_parse_color | ( | const gchar * | spec, |
GdkColor * | color | ||
) |
Definition at line 976 of file utils.c.
Referenced by prefs_init_dialog(), tools_color_chooser(), and utils_parse_color_to_bgr().
gint utils_parse_color_to_bgr | ( | const gchar * | spec | ) |
Definition at line 1005 of file utils.c.
References color, utils_color_to_bgr(), and utils_parse_color().
Referenced by parse_color(), and sci_set_mark_long_lines().
GDate * utils_parse_date | ( | const gchar * | input | ) |
Definition at line 2247 of file utils.c.
References NULL.
Referenced by utils_parse_and_format_build_date().
const gchar * utils_path_skip_root | ( | const gchar * | path | ) |
gchar * utils_remove_ext_from_filename | ( | const gchar * | filename | ) |
Removes the extension from filename and return the result in a newly allocated string.
filename | The filename to operate on. |
Definition at line 617 of file utils.c.
References filename, and NULL.
Referenced by build_replace_placeholder().
const gchar * utils_resource_dir | ( | GeanyResourceDirType | type | ) |
Definition at line 2301 of file utils.c.
References is_osx_bundle(), and NULL.
Referenced by get_plugin_path(), main_init(), main_lib(), main_locale_init(), prepare_run_cmd(), and setup_paths().
gdouble utils_scale_round | ( | gdouble | val, |
gdouble | factor | ||
) |
GIOChannel * utils_set_up_io_channel | ( | gint | fd, |
GIOCondition | cond, | ||
gboolean | nblock, | ||
GIOFunc | func, | ||
gpointer | data | ||
) |
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.
dir | The child's current working directory, or NULL to inherit parent's. |
argv | The child's argument vector. |
env | The child's environment, or NULL to inherit parent's. |
flags | Ignored. |
child_setup | Ignored. |
user_data | Ignored. |
child_pid | (out) The return location for child process ID, or NULL . |
error | The return location for error or NULL . |
TRUE
on success, FALSE
if an error was set. Definition at line 1680 of file utils.c.
References error(), NULL, and spawn_async().
Referenced by utils_start_new_geany_instance().
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.
dir | The child's current working directory, or NULL to inherit parent's. |
argv | The child's argument vector. |
env | The child's environment, or NULL to inherit parent's. |
flags | Ignored. |
child_setup | Ignored. |
user_data | Ignored. |
std_out | (out) The return location for child output, or NULL . |
std_err | (out) The return location for child error messages, or NULL . |
exit_status | (out) The child exit status, as returned by waitpid(), or NULL . |
error | The return location for error or NULL . |
TRUE
on success, FALSE
if an error was set. Definition at line 1647 of file utils.c.
References error(), NULL, and spawn_sync().
void utils_start_new_geany_instance | ( | const gchar * | doc_path | ) |
Definition at line 2348 of file utils.c.
References command, is_osx_bundle(), NULL, and utils_spawn_async().
Referenced by on_open_in_new_window_activate().
gint utils_str_casecmp | ( | const gchar * | s1, |
const gchar * | s2 | ||
) |
A replacement function for g_strncasecmp() to compare strings case-insensitive.
It converts both strings into lowercase using g_utf8_strdown() and then compare both strings using strcmp(). This is not completely accurate regarding locale-specific case sorting rules but seems to be a good compromise between correctness and performance.
The input strings should be in UTF-8 or locale encoding.
s1 | Pointer to first string or NULL . |
s2 | Pointer to second string or NULL . |
Definition at line 506 of file utils.c.
References NULL, and utf8_strdown().
Referenced by cmp_filetype(), compare_menu_item_labels(), get_doc_words(), is_plugin(), utils_get_config_files(), and utils_get_file_list_full().
gboolean utils_str_equal | ( | const gchar * | a, |
const gchar * | b | ||
) |
NULL-safe
string comparison.
Returns TRUE
if both a and b are NULL
or if a and b refer to valid strings which are equal.
a | Pointer to first string or NULL . |
b | Pointer to second string or NULL . |
TRUE
if a equals b, else FALSE
. Definition at line 599 of file utils.c.
References NULL.
Referenced by add_color_scheme_item(), add_item(), check_filtered(), compare_top_level_names(), demoproxy_probe(), document_activate_cb(), document_open_file_full(), document_save_file(), document_set_encoding(), encodings_radio_item_change_cb(), encodings_select_radio_item(), find_active_plugin_by_name(), find_by_filename(), find_calltip(), find_recent_file_item(), find_toplevel_iter(), find_tree_iter_dir(), gb_on_key_pressed(), get_custom_plugin_path(), get_entity(), get_symbol_name(), get_symbol_tooltip(), handle_buffer(), handle_forced_encoding(), insert_date(), load_dialog_prefs(), main_get_version_string(), on_document_save(), open_preferences_help(), plugin_configure(), plugin_loaded(), project_get_base_path(), project_open_cb(), queue_pos_matches(), search_show_find_in_files_dialog_full(), set_stop_button(), show_prompt(), sidebar_openfiles_update(), str_in_array(), tag_equal(), tb_editor_btn_add_clicked_cb(), tb_editor_btn_remove_clicked_cb(), tb_editor_drag_data_rcvd_cb(), tb_editor_foreach_used(), tb_editor_handler_start_element(), tb_editor_set_item_values(), toolbar_notify_style_cb(), tree_model_find_text(), tree_sort_func(), update_changed_state(), update_parents_table(), and utils_get_config_files().
gboolean utils_str_has_upper | ( | const gchar * | str | ) |
Definition at line 1452 of file utils.c.
Referenced by on_toggle_case1_activate().
gchar * utils_str_middle_truncate | ( | const gchar * | string, |
guint | truncate_length | ||
) |
Truncates the input string to a given length.
Characters are removed from the middle of the string, so the start and the end of string won't change.
string | Input string. |
truncate_length | The length in characters of the resulting string. |
Definition at line 549 of file utils.c.
References NULL.
Referenced by dialogs_show_file_properties(), document_get_basename_for_display(), and document_open_file_full().
gchar * utils_str_remove_chars | ( | gchar * | string, |
const gchar * | chars | ||
) |
Removes characters from a string, in place.
string | String to search. |
chars | Characters to remove. |
g_strdelimit
. Definition at line 1847 of file utils.c.
References chars, EMPTY, foreach_str, and NULL.
Referenced by keybindings_get_label(), tb_editor_set_item_values(), and ui_tool_button_new().
void utils_str_replace_all | ( | gchar ** | haystack, |
const gchar * | needle, | ||
const gchar * | replacement | ||
) |
Definition at line 692 of file utils.c.
References NULL, and utils_string_replace_all().
Referenced by build_run_cmd(), on_context_action1_activate(), and print_external().
gboolean utils_str_replace_escape | ( | gchar * | string, |
gboolean | keep_backslash | ||
) |
Definition at line 1071 of file utils.c.
References NULL.
Referenced by on_find_dialog_response(), and on_replace_dialog_response().
gint utils_string_find | ( | GString * | haystack, |
gint | start, | ||
gint | end, | ||
const gchar * | needle | ||
) |
Definition at line 1474 of file utils.c.
References EMPTY, NULL, pos, and utils_strpos().
Referenced by replace_cursor_markers(), utils_string_replace_all(), and utils_string_replace_first().
guint utils_string_regex_replace_all | ( | GString * | haystack, |
GRegex * | regex, | ||
guint | match_num, | ||
const gchar * | replace, | ||
gboolean | literal | ||
) |
Definition at line 1580 of file utils.c.
References NULL, and utils_string_replace().
Referenced by fix_indentation().
gint utils_string_replace | ( | GString * | str, |
gint | pos, | ||
gint | len, | ||
const gchar * | replace | ||
) |
Definition at line 1505 of file utils.c.
References pos.
Referenced by utils_string_regex_replace_all(), utils_string_replace_all(), and utils_string_replace_first().
guint utils_string_replace_all | ( | GString * | haystack, |
const gchar * | needle, | ||
const gchar * | replace | ||
) |
Replaces all occurrences of needle in haystack with replace.
As of Geany 0.16, replace can match needle, so the following will work:
haystack | The input string to operate on. This string is modified in place. |
needle | The string which should be replaced. |
replace | The replacement for needle. |
Definition at line 1529 of file utils.c.
References count, pos, utils_string_find(), and utils_string_replace().
Referenced by build_replace_placeholder(), editor_insert_text_block(), fix_indentation(), get_grep_options(), open_external(), pm_tree_search(), replace_static_values(), snippets_make_replacements(), snippets_replace_specials(), templates_replace_valist(), update_config(), utils_ensure_same_eol_characters(), utils_str_replace_all(), utils_tidy_path(), write_html_file(), and write_latex_file().
guint utils_string_replace_first | ( | GString * | haystack, |
const gchar * | needle, | ||
const gchar * | replace | ||
) |
Replaces only the first occurrence of needle in haystack with replace.
For details, see utils_string_replace_all().
haystack | The input string to operate on. This string is modified in place. |
needle | The string which should be replaced. |
replace | The replacement for needle. |
Definition at line 1563 of file utils.c.
References pos, utils_string_find(), and utils_string_replace().
Referenced by on_path_entry_activate(), and templates_replace_command().
gint utils_strpos | ( | const gchar * | haystack, |
const gchar * | needle | ||
) |
GEANY_EXPORT_SYMBOL gchar * utils_strv_find_common_prefix | ( | gchar ** | strv, |
gssize | strv_len | ||
) |
Definition at line 2055 of file utils.c.
References NULL.
Referenced by utils_strv_shorten_file_list().
GEANY_EXPORT_SYMBOL gchar * utils_strv_find_lcs | ( | gchar ** | strv, |
gssize | strv_len, | ||
const gchar * | delim | ||
) |
Definition at line 2090 of file utils.c.
References foreach_str, max, NULL, NZV, SETPTR, and strstr().
Referenced by utils_strv_shorten_file_list().
gchar ** utils_strv_join | ( | gchar ** | first, |
gchar ** | second | ||
) |
GEANY_EXPORT_SYMBOL gchar ** utils_strv_new | ( | const gchar * | first, |
... | |||
) |
gchar ** utils_strv_shorten_file_list | ( | gchar ** | file_names, |
gssize | file_names_len | ||
) |
Transform file names in a list to be shorter.
This function takes a list of file names (probably with absolute paths), and transforms the paths such that they are short but still unique. This is intended for dialogs which present the file list to the user, where the base name may result in duplicates (showing the full path might be inappropriate).
The algorthm strips the common prefix (e-g. the user's home directory) and replaces the longest common substring with an ellipsis ("...").
file_names | The list of strings to process. |
file_names_len | The number of strings contained in file_names. Can be -1 if it's terminated by NULL . |
NULL
. Use g_strfreev()
to free it.Definition at line 2169 of file utils.c.
References NULL, strstr(), utils_strv_find_common_prefix(), and utils_strv_find_lcs().
Referenced by show_goto_popup().
void utils_tidy_path | ( | gchar * | filename | ) |
Definition at line 1774 of file utils.c.
References filename, NULL, pos, strstr(), and utils_string_replace_all().
Referenced by document_new_file(), document_open_file_full(), and get_custom_plugin_path().
gboolean utils_wrap_string | ( | gchar * | string, |
gint | wrapstart | ||
) |
gint utils_write_file | ( | const gchar * | filename, |
const gchar * | text | ||
) |
Writes text into a file named filename.
If the file doesn't exist, it will be created. If it already exists, it will be overwritten.
g_file_set_contents()
instead if you don't need file permissions and other metadata to be preserved, as that always handles disk exhaustion safely.filename | The filename of the file to write, in locale encoding. |
text | The text to write into the file. |
errno
of the failed operation is returned. Definition at line 209 of file utils.c.
References errno, error(), FALLBACK, file_prefs, filename, geany_debug(), NULL, text, and GeanyFilePrefs::use_safe_file_saving.
Referenced by configuration_clear_default_session(), configuration_save(), configuration_save_default_session(), configure_response_cb(), create_config_dir(), filetypes_save_commands(), keybindings_write_to_file(), load_user_kb(), save_settings(), set_status(), stash_group_save_to_file(), tb_editor_write_markup(), write_config(), and write_data().