MassifG Utility functions

MassifG Utility functions — Useful utility functions

Synopsis

gchar *             massifg_utils_get_resource_file     (const gchar *filename);
void                massifg_utils_log_ignore            (const gchar *log_domain,
                                                         GLogLevelFlags log_level,
                                                         const gchar *message,
                                                         gpointer user_data);
void                massifg_utils_free_foreach          (gpointer data,
                                                         gpointer user_data);
void                massifg_utils_configure_debug_output
                                                        (void);
gchar *             massifg_str_copy_region             (gchar *src,
                                                         gint start_idx,
                                                         gint stop_idx);
int                 massifg_str_count_char              (gchar *str,
                                                         gchar c);
gchar *             massifg_str_cut_region              (gchar *src,
                                                         int cut_start,
                                                         int cut_end);

Description

More or less generic functions that do not belong in one single component

Details

massifg_utils_get_resource_file ()

gchar *             massifg_utils_get_resource_file     (const gchar *filename);

Find a resource file

First checks ./data/ in case the program is running from the build dir. Secondly, INSTALL_PREFIX/share in case of running from a non-system prefix. Then, checks the system folders as given by g_get_system_data_dirs()

Note: Not suitable for use in other applications, hardcodes the application name to "massifg"

filename :

file to search for

Returns :

the path to the file as a newly allocated string (free with g_free()), or NULL on failure

massifg_utils_log_ignore ()

void                massifg_utils_log_ignore            (const gchar *log_domain,
                                                         GLogLevelFlags log_level,
                                                         const gchar *message,
                                                         gpointer user_data);

Log function for use with glib logging facilities that just ignores input. Can be used to silence messages of a certain type, see massifg_utils_configure_debug_output()

log_domain :

log_domain

log_level :

log_level

message :

message

user_data :

user_data

massifg_utils_free_foreach ()

void                massifg_utils_free_foreach          (gpointer data,
                                                         gpointer user_data);

Utility function for freeing each element in a GList.

Elements freed using this function should have been allocated using g_alloc and derivatives. Meant to be used as a parameter to a g_(s)list_foreach call

data :

data

user_data :

user_data

massifg_utils_configure_debug_output ()

void                massifg_utils_configure_debug_output
                                                        (void);

Checks for the environment variable MASSIFG_DEBUG, if it is not "enable" or "all", debug output will be ignored


massifg_str_copy_region ()

gchar *             massifg_str_copy_region             (gchar *src,
                                                         gint start_idx,
                                                         gint stop_idx);

Copy a region of a string

Indexes start at 0

src :

String to copy from. Must be NULL terminated

start_idx :

Index in src to start copying from.

stop_idx :

Index in src to stop copying from. Must be smaller than the length of src

Returns :

a newly allocated string. Free with g_free()

massifg_str_count_char ()

int                 massifg_str_count_char              (gchar *str,
                                                         gchar c);

Count the number of time a character appears in a string

str :

String to search in. Must be NULL terminated.

c :

Character to count

Returns :

the number of occurrences of c in str

massifg_str_cut_region ()

gchar *             massifg_str_cut_region              (gchar *src,
                                                         int cut_start,
                                                         int cut_end);

Copy string, excluding a certain region

Indexes start at 0

src :

String to copy from

cut_start :

Index in src to start excluding

cut_end :

Index in src to stop excluding

Returns :

a newly allocated string. Free with g_free()