2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* utils.h - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-05-12 16:11:14 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
2005-11-27 20:49:50 +00:00
|
|
|
* $Id$
|
2005-11-22 12:26:26 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/**
|
|
|
|
* @file: utils.h
|
|
|
|
* General utility functions, non-GTK related.
|
|
|
|
*/
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#ifndef GEANY_UTILS_H
|
|
|
|
#define GEANY_UTILS_H 1
|
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Returns: TRUE if @a ptr points to a non-zero value. */
|
2007-04-30 16:16:15 +00:00
|
|
|
#define NZV(ptr) \
|
|
|
|
((ptr) && (ptr)[0])
|
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/**
|
|
|
|
* Free's @a ptr (if not @c NULL), then assigns @a result to it.
|
|
|
|
* @a result can be an expression using the 'old' value of @a ptr.
|
|
|
|
* It prevents a memory leak compared with: @code ptr = func(ptr); @endcode
|
|
|
|
**/
|
|
|
|
#define setptr(ptr, result) \
|
2007-05-24 16:00:48 +00:00
|
|
|
{\
|
2007-09-27 15:09:54 +00:00
|
|
|
gpointer setptr_tmp = ptr;\
|
2007-05-24 16:00:48 +00:00
|
|
|
ptr = result;\
|
2007-09-27 15:09:54 +00:00
|
|
|
g_free(setptr_tmp);\
|
2007-05-24 16:00:48 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-05-15 19:44:09 +00:00
|
|
|
void utils_start_browser(const gchar *uri);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-27 14:23:13 +00:00
|
|
|
gint utils_get_line_endings(const gchar* buffer, glong size);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
gboolean utils_isbrace(gchar c, gboolean include_angles);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
gboolean utils_is_opening_brace(gchar c, gboolean include_angles);
|
2006-06-29 18:22:11 +00:00
|
|
|
|
2005-12-12 16:19:30 +00:00
|
|
|
gint utils_write_file(const gchar *filename, const gchar *text);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
gchar *utils_find_open_xml_tag(const gchar sel[], gint size, gboolean check_tag);
|
|
|
|
|
2008-05-14 15:36:27 +00:00
|
|
|
const gchar *utils_get_eol_name(gint eol_mode);
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
gboolean utils_atob(const gchar *str);
|
|
|
|
|
|
|
|
gboolean utils_is_absolute_path(const gchar *path);
|
|
|
|
|
|
|
|
gdouble utils_scale_round(gdouble val, gdouble factor);
|
|
|
|
|
2006-12-07 16:09:45 +00:00
|
|
|
gboolean utils_str_equal(const gchar *a, const gchar *b);
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
gchar *utils_remove_ext_from_filename(const gchar *filename);
|
|
|
|
|
|
|
|
gchar utils_brace_opposite(gchar ch);
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
gchar *utils_get_hostname(void);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
gint utils_make_settings_dir(void);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-09-11 15:21:11 +00:00
|
|
|
gboolean utils_string_replace_all(GString *str, const gchar *needle, const gchar *replace);
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
gchar *utils_str_replace(gchar *haystack, const gchar *needle, const gchar *replacement);
|
|
|
|
|
2008-02-27 14:23:13 +00:00
|
|
|
gint utils_strpos(const gchar* haystack, const gchar *needle);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-11-17 13:09:19 +00:00
|
|
|
gchar *utils_get_date_time(const gchar *format, time_t *time_to_use);
|
2006-08-19 12:56:30 +00:00
|
|
|
|
2008-02-27 14:23:13 +00:00
|
|
|
gchar *utils_get_initials(const gchar *name);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
gboolean utils_get_setting_boolean(GKeyFile *config, const gchar *section, const gchar *key, const gboolean default_value);
|
|
|
|
|
|
|
|
gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gchar *key, const gint default_value);
|
|
|
|
|
|
|
|
gchar *utils_get_setting_string(GKeyFile *config, const gchar *section, const gchar *key, const gchar *default_value);
|
|
|
|
|
2005-12-11 02:16:02 +00:00
|
|
|
gchar *utils_get_hex_from_color(GdkColor *color);
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
const gchar *utils_get_default_dir_utf8(void);
|
2007-12-21 17:25:58 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
gchar *utils_get_current_file_dir_utf8(void);
|
2006-01-26 21:32:46 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void utils_beep(void);
|
2006-02-06 06:34:32 +00:00
|
|
|
|
2008-02-28 16:06:04 +00:00
|
|
|
gchar *utils_make_human_readable_str(guint64 size, gulong block_size,
|
2008-02-17 18:00:42 +00:00
|
|
|
gulong display_unit);
|
2006-02-22 13:41:50 +00:00
|
|
|
|
2006-07-27 20:57:13 +00:00
|
|
|
gint utils_strtod(const gchar *source, gchar **end, gboolean with_route);
|
2006-05-05 16:07:40 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
gchar *utils_get_current_time_string(void);
|
2006-07-01 12:02:30 +00:00
|
|
|
|
2007-03-01 21:45:43 +00:00
|
|
|
GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, gboolean nblock,
|
|
|
|
GIOFunc func, gpointer data);
|
2006-07-13 14:30:44 +00:00
|
|
|
|
2006-07-17 10:42:26 +00:00
|
|
|
gchar **utils_read_file_in_array(const gchar *filename);
|
|
|
|
|
2006-07-19 11:30:59 +00:00
|
|
|
gboolean utils_str_replace_escape(gchar *string);
|
|
|
|
|
2006-08-03 13:27:30 +00:00
|
|
|
gboolean utils_wrap_string(gchar *string, gint wrapstart);
|
|
|
|
|
2006-08-12 21:36:55 +00:00
|
|
|
gchar *utils_get_locale_from_utf8(const gchar *utf8_text);
|
|
|
|
|
|
|
|
gchar *utils_get_utf8_from_locale(const gchar *locale_text);
|
|
|
|
|
2007-04-23 15:52:44 +00:00
|
|
|
void utils_free_pointers(gpointer first, ...) G_GNUC_NULL_TERMINATED;
|
2007-01-14 17:09:17 +00:00
|
|
|
|
2008-02-27 14:23:13 +00:00
|
|
|
gchar **utils_strv_new(const gchar *first, ...) G_GNUC_NULL_TERMINATED;
|
2007-02-08 16:26:45 +00:00
|
|
|
|
2007-03-10 17:26:03 +00:00
|
|
|
gint utils_mkdir(const gchar *path, gboolean create_parent_dirs);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-05-11 11:42:00 +00:00
|
|
|
GSList *utils_get_file_list(const gchar *path, guint *length, GError **error);
|
|
|
|
|
2007-09-07 19:01:55 +00:00
|
|
|
gboolean utils_str_has_upper(const gchar *str);
|
|
|
|
|
2008-01-06 19:59:01 +00:00
|
|
|
gint utils_is_file_writeable(const gchar *locale_filename);
|
|
|
|
|
2008-02-24 10:27:32 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
gboolean utils_spawn_async(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags flags,
|
|
|
|
GSpawnChildSetupFunc child_setup, gpointer user_data, GPid *child_pid,
|
|
|
|
GError **error);
|
|
|
|
|
2008-07-20 18:07:53 +00:00
|
|
|
void utils_reload_configuration(void);
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
#endif
|