Start making SardemFF happy. Use g_return_if_fail

This commit is contained in:
Dave Davenport 2016-01-08 09:16:59 +01:00
parent 20b2d658a0
commit dc8fb4f202
13 changed files with 55 additions and 27 deletions

View File

@ -19,7 +19,7 @@ typedef char * ( *_mode_get_completion )( const Mode *sw, unsigned int selected_
*/
typedef int ( *_mode_token_match )( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
typedef void ( *__mode_init )( Mode *sw );
typedef int ( *__mode_init )( Mode *sw );
typedef unsigned int ( *__mode_get_num_entries )( const Mode *sw );

View File

@ -53,8 +53,10 @@ typedef enum
* @param mode The mode to initialize
*
* Initialize mode
*
* @returns FALSE if there was a failure, TRUE if successful
*/
void mode_init ( Mode *mode );
int mode_init ( Mode *mode );
/**
* @param mode The mode to destroy

View File

@ -69,5 +69,15 @@ __attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
* @returns EXIT_FAILURE if failed to create dialog, EXIT_SUCCESS if succesfull
*/
int show_error_message ( const char *msg, int markup );
#define ERROR_MSG( a ) a "\n" \
"If you suspect this is caused by a bug in rofi,\n" \
"please report the following information to rofi's github page:\n" \
" * The generated commandline output when the error occored.\n" \
" * Output of -dump-xresource\n" \
" * Steps to reproduce\n" \
" * The version of rofi you are running\n\n" \
" <i>https://github.com/DaveDavenport/rofi/</i>"
#define ERROR_MSG_MARKUP TRUE
/*@}*/
#endif

View File

@ -39,14 +39,14 @@ typedef struct
typedef enum
{
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
} TextboxFlags;
typedef enum

View File

@ -99,7 +99,7 @@ static void combi_mode_parse_switchers ( Mode *sw )
g_free ( switcher_str );
}
static void combi_mode_init ( Mode *sw )
static int combi_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
CombiModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
@ -108,7 +108,9 @@ static void combi_mode_init ( Mode *sw )
pd->starts = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
pd->lengths = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) {
mode_init ( pd->switchers[i] );
if ( !mode_init ( pd->switchers[i] ) ) {
return FALSE;
}
}
if ( pd->cmd_list_length == 0 ) {
pd->cmd_list_length = 0;
@ -120,6 +122,7 @@ static void combi_mode_init ( Mode *sw )
}
}
}
return TRUE;
}
static unsigned int combi_mode_get_num_entries ( const Mode *sw )
{

View File

@ -243,10 +243,10 @@ static void dmenu_mode_free ( Mode *sw )
}
}
static void dmenu_mode_init ( Mode *sw )
static int dmenu_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) != NULL ) {
return;
return TRUE;
}
mode_set_private_data ( sw, g_malloc0 ( sizeof ( DmenuModePrivateData ) ) );
DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw );
@ -302,7 +302,7 @@ static void dmenu_mode_init ( Mode *sw )
error_dialog ( msg, TRUE );
g_free ( msg );
g_free ( estr );
return;
return TRUE;
}
g_free ( estr );
}
@ -310,6 +310,7 @@ static void dmenu_mode_init ( Mode *sw )
if ( fd != NULL ) {
fclose ( fd );
}
return TRUE;
}
static int dmenu_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )

View File

@ -227,13 +227,14 @@ static void get_apps ( DRunModePrivateData *pd )
}
}
static void drun_mode_init ( Mode *sw )
static int drun_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
DRunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
get_apps ( pd );
}
return TRUE;
}
static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )

View File

@ -304,13 +304,15 @@ static char ** get_apps ( unsigned int *length )
return retv;
}
static void run_mode_init ( Mode *sw )
static int run_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
RunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
pd->cmd_list = get_apps ( &( pd->cmd_list_length ) );
}
return TRUE;
}
static unsigned int run_mode_get_num_entries ( const Mode *sw )

View File

@ -98,13 +98,14 @@ typedef struct _ScriptModePrivateData
unsigned int cmd_list_length;
} ScriptModePrivateData;
static void script_mode_init ( Mode *sw )
static int script_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
pd->cmd_list = get_script_output ( (const char *) sw->ed, &( pd->cmd_list_length ) );
}
return TRUE;
}
static unsigned int script_mode_get_num_entries ( const Mode *sw )
{

View File

@ -362,13 +362,14 @@ typedef struct _SSHModePrivateData
* Initializes the SSH Mode private data object and
* loads the relevant ssh information.
*/
static void ssh_mode_init ( Mode *sw )
static int ssh_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
SSHModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
pd->hosts_list = get_ssh ( &( pd->hosts_list_length ) );
}
return TRUE;
}
/**

View File

@ -495,21 +495,23 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
}
}
}
static void window_mode_init ( Mode *sw )
static int window_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
ModeModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
_window_mode_load_data ( sw, FALSE );
}
return TRUE;
}
static void window_mode_init_cd ( Mode *sw )
static int window_mode_init_cd ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
ModeModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
_window_mode_load_data ( sw, TRUE );
}
return TRUE;
}
static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **input,
unsigned int selected_line )

View File

@ -10,11 +10,12 @@
* @{
*/
void mode_init ( Mode *mode )
int mode_init ( Mode *mode )
{
g_assert ( mode != NULL );
g_assert ( mode->_init != NULL );
g_return_val_if_fail ( mode != NULL, FALSE );
g_return_val_if_fail ( mode->_init != NULL, FALSE );
mode->_init ( mode );
return TRUE;
}
void mode_destroy ( Mode *mode )
@ -63,7 +64,7 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel
{
g_assert ( mode != NULL );
g_assert ( mode->_result != NULL );
g_assert ( (*input) != NULL );
g_assert ( ( *input ) != NULL );
return mode->_result ( mode, menu_retv, input, selected_line );
}
@ -101,7 +102,7 @@ int mode_check_keybinding ( const Mode *mode, KeySym key, unsigned int modstate
void mode_free ( Mode **mode )
{
g_assert ( mode != NULL );
g_assert ( (*mode) != NULL );
g_assert ( ( *mode ) != NULL );
if ( ( *mode )->keycfg != NULL ) {
g_free ( ( *mode )->keycfg );
( *mode )->keycfg = NULL;

View File

@ -1870,7 +1870,11 @@ static void run_switcher ( ModeMode mode )
// Otherwise check if requested mode is enabled.
char *input = g_strdup ( config.filter );
for ( unsigned int i = 0; i < num_modi; i++ ) {
mode_init ( modi[i].sw );
if ( !mode_init ( modi[i].sw ) ) {
error_dialog ( ERROR_MSG ( "Failed to initialize all the modi." ), ERROR_MSG_MARKUP );
teardown ( pfd );
return;
}
}
do {
ModeMode retv;