utils

utils

Synopsis

enum                TimesType;
gchar *             gebr_g_string_remove_accents        (gchar *title);
void                gebr_g_string_replace               (GString *string,
                                                         const gchar *oldtext,
                                                         const gchar *newtext);
void                gebr_g_string_replace_first_ref     (GString *string,
                                                         const gchar *oldtext,
                                                         const gchar *newtext);
gboolean            gebr_g_string_starts_with           (GString *string,
                                                         const gchar *val);
gboolean            gebr_g_string_ends_with             (GString *string,
                                                         const gchar *val);
gboolean            gebr_append_filename_extension      (GString *filename,
                                                         const gchar *extension);
gboolean            gebr_path_is_at_home                (const gchar *path);
gboolean            gebr_path_use_home_variable         (GString *path);
gboolean            gebr_path_resolve_home_variable     (GString *path);
void                gebr_path_set_to                    (GString *path,
                                                         gboolean relative);
GString *           gebr_temp_directory_create          (void);
void                gebr_temp_directory_destroy         (GString *path);
GString *           gebr_make_unique_filename           (const gchar *template);
GString *           gebr_make_temp_filename             (const gchar *template);
gint                gebr_system                         (const gchar *cmd,
                                                         ...);
gboolean            gebr_dir_has_files                  (const gchar *dir_path);
int                 gebr_home_mode                      (void);
gboolean            gebr_create_config_dirs             (void);
gchar *             gebr_locale_to_utf8                 (const gchar *string);
gboolean            g_key_file_has_key_woe              (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key);
GString *           gebr_g_key_file_load_string_key     (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key,
                                                         const gchar *default_value);
gboolean            gebr_g_key_file_load_boolean_key    (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key,
                                                         gboolean default_value);
int                 gebr_g_key_file_load_int_key        (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key,
                                                         int default_value);
gboolean            gebr_g_key_file_has_key             (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key);
gboolean            gebr_g_key_file_remove_key          (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key);
#define             gebr_foreach_gslist_hyg             (element,
                                                         list,
                                                         hygid)
#define             gebr_foreach_gslist                 (element,
                                                         list)
#define             gebr_glist_foreach_hyg              (element,
                                                         list,
                                                         hygid)
#define             gebr_glist_foreach                  (element,
                                                         list)
#define             gebr_directory_foreach_file_hyg     (filename,
                                                         directory,
                                                         hygid)
#define             gebr_directory_foreach_file         (filename,
                                                         directory)
const gchar *       gebr_validate_int                   (const gchar *text_value,
                                                         const gchar *min,
                                                         const gchar *max);
const gchar *       gebr_validate_float                 (const gchar *text_value,
                                                         const gchar *min,
                                                         const gchar *max);
int                 g_strcmp0                           (const char *str1,
                                                         const char *str2);
gboolean            gebr_realpath_equal                 (const gchar *path1,
                                                         const gchar *path2);
gchar *             gebr_str_escape                     (const gchar *str);
gchar *             gebr_date_get_localized             (const gchar *format,
                                                         const gchar *locale);
gchar *             gebr_id_random_create               (gssize bytes);
gchar *             gebr_lock_file                      (const gchar *pathname,
                                                         const gchar *new_lock_content,
                                                         gboolean symlink);
gchar *             gebr_str_word_before_pos            (const gchar *str,
                                                         gint *pos);
gchar *             gebr_str_remove_trailing_zeros      (gchar *str);
gboolean            gebr_str_canonical_var_name         (const gchar *keyword,
                                                         gchar **new_value,
                                                         GError **error);
gchar *             gebr_calculate_relative_time        (GTimeVal *time1,
                                                         GTimeVal *time2,
                                                         TimesType *type,
                                                         gdouble *delta);
gdouble             gebr_get_lower_bound_for_type       (TimesType type);
gint                gebr_get_number_of_time_controls    ();
gchar *             gebr_get_control_text_for_type      (TimesType type);
gchar *             gebr_calculate_detailed_relative_time
                                                        (GTimeVal *time1,
                                                         GTimeVal *time2);
gchar *             gebr_compute_diff_iso_times         (const gchar *iso_time1,
                                                         const gchar *iso_time2);
gint                gebr_compute_diff_clock_to_me       (const gchar *iso_time1);
gboolean            gebr_utf8_is_asc_alnum              (const gchar *str);
gchar *             gebr_utf8_strstr                    (const gchar *haystack,
                                                         const gchar *needle);
gint                gebr_calculate_number_of_processors (gint total_nprocs,
                                                         gdouble aggressive);
void                gebr_pairstrfreev                   (gchar ***strv);
gchar *             gebr_remove_path_prefix             (const gchar *prefix,
                                                         const gchar *path);
gchar *             gebr_relativise_old_home_path       (const gchar *path_string);
gchar *             gebr_relativise_home_path           (const gchar *path_string,
                                                         const gchar *mount_point,
                                                         const gchar *home);
gchar *             gebr_relativise_path                (const gchar *path_string,
                                                         const gchar *mount_point,
                                                         gchar ***pvector);
gchar *             gebr_resolve_relative_path          (const char *path,
                                                         gchar ***pvector);
gchar ***           gebr_generate_paths_with_home       (const gchar *home);
void                gebr_gtk_bookmarks_add_paths        (const gchar *filename,
                                                         const gchar *uri_prefix,
                                                         gchar ***paths);
void                gebr_gtk_bookmarks_remove_paths     (const gchar *filename,
                                                         gchar ***paths);
gboolean            gebr_verify_starting_slash          (const gchar *string);
gboolean            gebr_validate_path                  (const gchar *path,
                                                         gchar ***paths,
                                                         gchar **err_msg);
gint                gebr_strv_indexof                   (const gchar **strv,
                                                         const gchar *value);
gboolean            gebr_generate_key                   ();
gboolean            gebr_add_remove_ssh_key             (gboolean remove);
gboolean            gebr_check_if_server_accepts_key    (const gchar *hostname,
                                                         gboolean is_maestro);
void                gebr_remove_temporary_file          (const gchar *hostname,
                                                         gboolean is_maestro);
gchar *             gebr_get_address_without_user       (const gchar *address);
gboolean            gebr_verify_address_without_username
                                                        (const gchar *address);
gboolean            gebr_kill_by_port                   (gint port);
gchar *             gebr_key_filename                   (gboolean public);
gchar *             gebr_create_id_with_current_time    ();
GList *             gebr_double_list_to_list            (GList *double_list);
gboolean            gebr_gzfile_get_contents            (const gchar *filename,
                                                         GString *contents,
                                                         gchar **error);
gboolean            gebr_callback_true                  (void);
void                gebr_string_freeall                 (GString *string);

Description

Details

enum TimesType

typedef enum {
	TIME_NONE,
	TIME_MOMENTS_AGO,
	TIME_HOURS_AGO,
	TIME_DAYS_AGO,
	TIME_WEEKS_AGO,
	TIME_MONTHS_AGO,
	TIME_YEARS_AGO,
	TIME_N_TYPES,
} TimesType;

gebr_g_string_remove_accents ()

gchar *             gebr_g_string_remove_accents        (gchar *title);

Replace accented characters on a string to non accented characters. If character is non ASCII, it is replaced to ""

title :

the text with accents to be removed

gebr_g_string_replace ()

void                gebr_g_string_replace               (GString *string,
                                                         const gchar *oldtext,
                                                         const gchar *newtext);

Replace each reference of oldtext in string with newtext. If newtext if NULL, then each reference of oldtext found is removed.

string :

The string to with the text.

oldtext :

The text to be replaced.

newtext :

The text to replace oldtext.

gebr_g_string_replace_first_ref ()

void                gebr_g_string_replace_first_ref     (GString *string,
                                                         const gchar *oldtext,
                                                         const gchar *newtext);

gebr_g_string_starts_with ()

gboolean            gebr_g_string_starts_with           (GString *string,
                                                         const gchar *val);

gebr_g_string_ends_with ()

gboolean            gebr_g_string_ends_with             (GString *string,
                                                         const gchar *val);

gebr_append_filename_extension ()

gboolean            gebr_append_filename_extension      (GString *filename,
                                                         const gchar *extension);

gebr_path_is_at_home ()

gboolean            gebr_path_is_at_home                (const gchar *path);

gebr_path_use_home_variable ()

gboolean            gebr_path_use_home_variable         (GString *path);

gebr_path_resolve_home_variable ()

gboolean            gebr_path_resolve_home_variable     (GString *path);

gebr_path_set_to ()

void                gebr_path_set_to                    (GString *path,
                                                         gboolean relative);

gebr_temp_directory_create ()

GString *           gebr_temp_directory_create          (void);

gebr_temp_directory_destroy ()

void                gebr_temp_directory_destroy         (GString *path);

gebr_make_unique_filename ()

GString *           gebr_make_unique_filename           (const gchar *template);

gebr_make_temp_filename ()

GString *           gebr_make_temp_filename             (const gchar *template);

gebr_system ()

gint                gebr_system                         (const gchar *cmd,
                                                         ...);

gebr_dir_has_files ()

gboolean            gebr_dir_has_files                  (const gchar *dir_path);

gebr_home_mode ()

int                 gebr_home_mode                      (void);

gebr_create_config_dirs ()

gboolean            gebr_create_config_dirs             (void);

gebr_locale_to_utf8 ()

gchar *             gebr_locale_to_utf8                 (const gchar *string);

g_key_file_has_key_woe ()

gboolean            g_key_file_has_key_woe              (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key);

gebr_g_key_file_load_string_key ()

GString *           gebr_g_key_file_load_string_key     (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key,
                                                         const gchar *default_value);

gebr_g_key_file_load_boolean_key ()

gboolean            gebr_g_key_file_load_boolean_key    (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key,
                                                         gboolean default_value);

gebr_g_key_file_load_int_key ()

int                 gebr_g_key_file_load_int_key        (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key,
                                                         int default_value);

gebr_g_key_file_has_key ()

gboolean            gebr_g_key_file_has_key             (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key);

gebr_g_key_file_remove_key ()

gboolean            gebr_g_key_file_remove_key          (GKeyFile *key_file,
                                                         const gchar *group,
                                                         const gchar *key);

gebr_foreach_gslist_hyg()

#define             gebr_foreach_gslist_hyg(element, list, hygid)

gebr_foreach_gslist()

#define             gebr_foreach_gslist(element, list)

gebr_glist_foreach_hyg()

#define             gebr_glist_foreach_hyg(element, list, hygid)

gebr_glist_foreach()

#define             gebr_glist_foreach(element, list)

gebr_directory_foreach_file_hyg()

#define             gebr_directory_foreach_file_hyg(filename, directory, hygid)

gebr_directory_foreach_file()

#define             gebr_directory_foreach_file(filename, directory)

gebr_validate_int ()

const gchar *       gebr_validate_int                   (const gchar *text_value,
                                                         const gchar *min,
                                                         const gchar *max);

gebr_validate_float ()

const gchar *       gebr_validate_float                 (const gchar *text_value,
                                                         const gchar *min,
                                                         const gchar *max);

g_strcmp0 ()

int                 g_strcmp0                           (const char *str1,
                                                         const char *str2);

gebr_realpath_equal ()

gboolean            gebr_realpath_equal                 (const gchar *path1,
                                                         const gchar *path2);

Compares if path1 and path2 resolves to the same file. The paths compared for equality by calling g_stat() on both of them and comparing their inode parameters are the same.

path1 :

the first path

path2 :

the second path

Returns :

TRUE if path1 points to the same file/directory as path2. FALSE otherwise, including if one or both of then does not exists in the file system.

gebr_str_escape ()

gchar *             gebr_str_escape                     (const gchar *str);

Escapes all backslashes and quotes in a string. It is based on glib's g_strescape.

str :

the string to be escaped

Returns :

a newly allocated string.

gebr_date_get_localized ()

gchar *             gebr_date_get_localized             (const gchar *format,
                                                         const gchar *locale);

gebr_id_random_create ()

gchar *             gebr_id_random_create               (gssize bytes);

gebr_lock_file ()

gchar *             gebr_lock_file                      (const gchar *pathname,
                                                         const gchar *new_lock_content,
                                                         gboolean symlink);

gebr_str_word_before_pos ()

gchar *             gebr_str_word_before_pos            (const gchar *str,
                                                         gint *pos);

gebr_str_remove_trailing_zeros ()

gchar *             gebr_str_remove_trailing_zeros      (gchar *str);

Modifies str inplace by removing trailing zeros.

Returns :

The same str, but modified.

gebr_str_canonical_var_name ()

gboolean            gebr_str_canonical_var_name         (const gchar *keyword,
                                                         gchar **new_value,
                                                         GError **error);

keyword :

The keyword to be canonized. (not modified)

new_value :

Returns a new alocated string with the canonized value of keyword.

error :

A GError (not used until now)

Returns :

TRUE if everthing is ok. False otherwise.

gebr_calculate_relative_time ()

gchar *             gebr_calculate_relative_time        (GTimeVal *time1,
                                                         GTimeVal *time2,
                                                         TimesType *type,
                                                         gdouble *delta);

time1 :

The first date to compare

time2 :

The second date to compare

Returns :

A message (string) of the relative time and NULL if time2 is older than time1.

gebr_get_lower_bound_for_type ()

gdouble             gebr_get_lower_bound_for_type       (TimesType type);

gebr_get_number_of_time_controls ()

gint                gebr_get_number_of_time_controls    ();

gebr_get_control_text_for_type ()

gchar *             gebr_get_control_text_for_type      (TimesType type);

Return:


gebr_calculate_detailed_relative_time ()

gchar *             gebr_calculate_detailed_relative_time
                                                        (GTimeVal *time1,
                                                         GTimeVal *time2);

gebr_compute_diff_iso_times ()

gchar *             gebr_compute_diff_iso_times         (const gchar *iso_time1,
                                                         const gchar *iso_time2);

gebr_compute_diff_clock_to_me ()

gint                gebr_compute_diff_clock_to_me       (const gchar *iso_time1);

gebr_utf8_is_asc_alnum ()

gboolean            gebr_utf8_is_asc_alnum              (const gchar *str);

str :

The string to check

Returns :

TRUE if str is ASC and alpha-numerical.

gebr_utf8_strstr ()

gchar *             gebr_utf8_strstr                    (const gchar *haystack,
                                                         const gchar *needle);

Searches for needle in haystack and returns a pointer to the begging of the substring or NULL if it was not found.


gebr_calculate_number_of_processors ()

gint                gebr_calculate_number_of_processors (gint total_nprocs,
                                                         gdouble aggressive);

Calculate real number of processors will be used

total_nprocs :

Number of processors of a server

aggressive :

Aggressive percentage (slider)

gebr_pairstrfreev ()

void                gebr_pairstrfreev                   (gchar ***strv);

Frees a vector of pairs of strings.


gebr_remove_path_prefix ()

gchar *             gebr_remove_path_prefix             (const gchar *prefix,
                                                         const gchar *path);

Remove prefix from path


gebr_relativise_old_home_path ()

gchar *             gebr_relativise_old_home_path       (const gchar *path_string);

Change $HOME of path_string to <HOME>


gebr_relativise_home_path ()

gchar *             gebr_relativise_home_path           (const gchar *path_string,
                                                         const gchar *mount_point,
                                                         const gchar *home);

Substitute home with the prefix HOME pvector is a vector of pair of strings, the first entry is an alias and the second is an absolute path.


gebr_relativise_path ()

gchar *             gebr_relativise_path                (const gchar *path_string,
                                                         const gchar *mount_point,
                                                         gchar ***pvector);

Substitute path with the longest prefix in pvector. pvector is a vector of pair of strings, the first entry is an alias and the second is an absolute path.


gebr_resolve_relative_path ()

gchar *             gebr_resolve_relative_path          (const char *path,
                                                         gchar ***pvector);

Transfors a relative path in absolute path


gebr_generate_paths_with_home ()

gchar ***           gebr_generate_paths_with_home       (const gchar *home);

gebr_gtk_bookmarks_add_paths ()

void                gebr_gtk_bookmarks_add_paths        (const gchar *filename,
                                                         const gchar *uri_prefix,
                                                         gchar ***paths);

Add bookmarks on filename file with uri_prefix and base paths set on vector paths, and include suffix (GeBR) on name to identify


gebr_gtk_bookmarks_remove_paths ()

void                gebr_gtk_bookmarks_remove_paths     (const gchar *filename,
                                                         gchar ***paths);

Remove bookmarks according paths for filename


gebr_verify_starting_slash ()

gboolean            gebr_verify_starting_slash          (const gchar *string);

gebr_validate_path ()

gboolean            gebr_validate_path                  (const gchar *path,
                                                         gchar ***paths,
                                                         gchar **err_msg);

gebr_strv_indexof ()

gint                gebr_strv_indexof                   (const gchar **strv,
                                                         const gchar *value);

gebr_generate_key ()

gboolean            gebr_generate_key                   ();

gebr_add_remove_ssh_key ()

gboolean            gebr_add_remove_ssh_key             (gboolean remove);

gebr_check_if_server_accepts_key ()

gboolean            gebr_check_if_server_accepts_key    (const gchar *hostname,
                                                         gboolean is_maestro);

gebr_remove_temporary_file ()

void                gebr_remove_temporary_file          (const gchar *hostname,
                                                         gboolean is_maestro);

gebr_get_address_without_user ()

gchar *             gebr_get_address_without_user       (const gchar *address);

Get substring after the first @ and before the first space In case there's no @, get the substring before the first space


gebr_verify_address_without_username ()

gboolean            gebr_verify_address_without_username
                                                        (const gchar *address);

gebr_kill_by_port ()

gboolean            gebr_kill_by_port                   (gint port);

gebr_key_filename ()

gchar *             gebr_key_filename                   (gboolean public);

gebr_create_id_with_current_time ()

gchar *             gebr_create_id_with_current_time    ();

gebr_double_list_to_list ()

GList *             gebr_double_list_to_list            (GList *double_list);

gebr_gzfile_get_contents ()

gboolean            gebr_gzfile_get_contents            (const gchar *filename,
                                                         GString *contents,
                                                         gchar **error);

filename :

The name of gzipped file

contents :

a GString to fill the contents of file

error :

an error message or NULL

Returns :

FALSE if have some error, TRUE otherwise

gebr_callback_true ()

gboolean            gebr_callback_true                  (void);

Returns :

TRUE.

gebr_string_freeall ()

void                gebr_string_freeall                 (GString *string);

Equivalent to calling g_string_free(string, TRUE).