girara
Macros | Enumerations | Functions
utils.h File Reference
#include <stdio.h>
#include "types.h"
#include "macros.h"
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define girara_debug(...)   _girara_debug(__FUNCTION__, __LINE__, GIRARA_DEBUG, __VA_ARGS__)
 
#define girara_info(...)   _girara_debug(__FUNCTION__, __LINE__, GIRARA_INFO, __VA_ARGS__)
 
#define girara_warning(...)   _girara_debug(__FUNCTION__, __LINE__, GIRARA_WARNING, __VA_ARGS__)
 
#define girara_error(...)   _girara_debug(__FUNCTION__, __LINE__, GIRARA_ERROR, __VA_ARGS__)
 

Enumerations

enum  girara_xdg_path_t {
  XDG_CONFIG, XDG_DATA, XDG_CONFIG_DIRS, XDG_DATA_DIRS,
  XDG_CACHE
}
 

Functions

char * girara_get_home_directory (const char *user)
 
char * girara_get_xdg_path (girara_xdg_path_t path)
 
bool girara_xdg_open (const char *uri)
 
girara_list_tgirara_split_path_array (const char *patharray)
 
char * girara_fix_path (const char *path)
 
FILE * girara_file_open (const char *path, const char *mode)
 
char * girara_file_read_line (FILE *file)
 
char * girara_file_read (const char *path)
 
char * girara_file_read2 (FILE *file)
 
void girara_clean_line (char *line)
 
void * girara_safe_realloc (void **ptr, size_t size) GIRARA_ALLOC_SIZE(2)
 
void _girara_debug (const char *function, int line, girara_debug_level_t level, const char *format,...) GIRARA_PRINTF(4
 
void girara_debug_level_t girara_get_debug_level ()
 
void girara_set_debug_level (girara_debug_level_t level)
 
char * girara_escape_string (const char *value)
 
char * girara_replace_substring (const char *string, const char *old, const char *new)
 
bool girara_exec_with_argument_list (girara_session_t *session, girara_list_t *argument_list)
 

Macro Definition Documentation

#define girara_debug (   ...)    _girara_debug(__FUNCTION__, __LINE__, GIRARA_DEBUG, __VA_ARGS__)

Prints a debug message. The arguments are passed to _girara_debug as last argument.

Definition at line 120 of file utils.h.

#define girara_error (   ...)    _girara_debug(__FUNCTION__, __LINE__, GIRARA_ERROR, __VA_ARGS__)

Prints an error message. The arguments are passed to _girara_debug as last argument.

Definition at line 135 of file utils.h.

#define girara_info (   ...)    _girara_debug(__FUNCTION__, __LINE__, GIRARA_INFO, __VA_ARGS__)

Prints an info message. The arguments are passed to _girara_debug as last argument.

Definition at line 125 of file utils.h.

#define girara_warning (   ...)    _girara_debug(__FUNCTION__, __LINE__, GIRARA_WARNING, __VA_ARGS__)

Prints a warning message. The arguments are passed to _girara_debug as last argument.

Definition at line 130 of file utils.h.

Enumeration Type Documentation

Enum for directories specified in the XDG specification.

Enumerator
XDG_CONFIG 

XDG_CONFIG_HOME

XDG_DATA 

XDG_DATA_HOME

XDG_CONFIG_DIRS 

XDG_CONFIG_DIRS

XDG_DATA_DIRS 

XDG_DATA_DIRS

XDG_CACHE 

XDG_CACHE_HOME

Definition at line 13 of file utils.h.

Function Documentation

void _girara_debug ( const char *  function,
int  line,
girara_debug_level_t  level,
const char *  format,
  ... 
)

Print a message.

Parameters
functionThe calling function
lineThe line of the call
levelThe debug level of the message.
formatprintf like format string
void girara_clean_line ( char *  line)

Trims and cleans a line from multiple whitespaces

Parameters
line
char* girara_escape_string ( const char *  value)

Escape \, \t, ", ' and spaces in strings.

Parameters
valueThe string to be escaped.
Returns
The escaped string. Needs to be freed with g_free.
bool girara_exec_with_argument_list ( girara_session_t *  session,
girara_list_t argument_list 
)

Execute command from argument list

Parameters
sessionThe used girara session
argument_listThe argument list
Returns
true if no error occured
FILE* girara_file_open ( const char *  path,
const char *  mode 
)

Open a file in a safe way

Parameters
pathPath of the file
modeMode that the file should be opened
Returns
NULL if an error occured
char* girara_file_read ( const char *  path)

Reads the whole content from a file. Returned string has to be freed.

Parameters
pathPath to the file
Returns
Read file or NULL if an error occured
char* girara_file_read2 ( FILE *  file)

Reads the whole content from a file. Returned string has to be freed.

Parameters
filefile to read
Returns
Read file or NULL if an error occured
char* girara_file_read_line ( FILE *  file)

Reads a line from the file. The returned string has to be released with g_free.

Parameters
fileThe file stream
Returns
Read line or NULL if an error occured
char* girara_fix_path ( const char *  path)

Returns a "fixed" version of path. Which means, it will be an absolute path and fully expanded. ~ and ~user will be replaced by the current user's home directory (user's home directory respectively).

Parameters
paththe path to "fix".
Returns
the "fixed" path (needs to be freed with g_free).
void girara_debug_level_t girara_get_debug_level ( )

Get the debug level.

Returns
The debug level.
char* girara_get_home_directory ( const char *  user)

Returns the home directory for the given user. $HOME is prefered over the value from g_get_home_dir.

Parameters
usera username or NULL to get home directory of the current user.
Returns
a string containing the path to the user's home directory (needs to be freed with g_free) or NULL if the user doesn't exist.
char* girara_get_xdg_path ( girara_xdg_path_t  path)

Returns a specific path specified in the XDG specification. ~ in paths will not be expanded.

Parameters
pathwhich path to get
Returns
a string containing the requested patch (needs to be freed with g_free) or NULL for invalid values.
char* girara_replace_substring ( const char *  string,
const char *  old,
const char *  new 
)

Replaces all occurences of old in string with new and returns a new allocated string

Parameters
stringThe original string
oldString to replace
newReplacement string
Returns
new allocated string, needs to be freed with g_free
void* girara_safe_realloc ( void **  ptr,
size_t  size 
)

Changes the size of the memory block by wrapping a realloc function call In addition it frees the old memory block if realloc fails.

Parameters
ptrMemory space
sizeNumber of bytes
Returns
Pointer to the allocated memory block or NULL
void girara_set_debug_level ( girara_debug_level_t  level)

Set the debug level. Any message with a level lower than the debug level will be discarded.

Parameters
levelThe new debug level.
girara_list_t* girara_split_path_array ( const char *  patharray)

Splits paths seperated by : (as in $PATH) into a list.

Parameters
patharrayString like $PATH to split
Returns
a list of paths and NULL on failure.
bool girara_xdg_open ( const char *  uri)

Opens a URI with xdg-open.

Parameters
urithe URI to be opened.
Returns
true on success, false otherwise