diff options
Diffstat (limited to 'source/dialogs/script.c')
-rw-r--r-- | source/dialogs/script.c | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 514e43ba..254fab0b 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -45,18 +45,16 @@ #include "mode-private.h" - #include "rofi-icon-fetcher.h" #include "dialogs/dmenuscriptshared.h" - typedef struct { /** ID of the current script. */ unsigned int id; /** List of visible items. */ - DmenuScriptEntry *cmd_list; + DmenuScriptEntry *cmd_list; /** length list of visible items. */ unsigned int cmd_list_length; @@ -77,18 +75,18 @@ typedef struct */ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, size_t length ) { - size_t length_key = 0;//strlen ( line ); + size_t length_key = 0; //strlen ( line ); while ( length_key <= length && buffer[length_key] != '\x1f' ) { length_key++; } if ( length_key < length ) { buffer[length_key] = '\0'; char *value = buffer + length_key + 1; - if ( strcasecmp(buffer, "icon" ) == 0 ) { - entry->icon_name = g_strdup(value); + if ( strcasecmp ( buffer, "icon" ) == 0 ) { + entry->icon_name = g_strdup ( value ); } - if ( strcasecmp(buffer, "meta" ) == 0 ) { - entry->meta = g_strdup(value); + if ( strcasecmp ( buffer, "meta" ) == 0 ) { + entry->meta = g_strdup ( value ); } } } @@ -131,11 +129,11 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg, unsigned int *length ) { - int fd = -1; - GError *error = NULL; - DmenuScriptEntry *retv = NULL; - char **argv = NULL; - int argc = 0; + int fd = -1; + GError *error = NULL; + DmenuScriptEntry *retv = NULL; + char **argv = NULL; + int argc = 0; *length = 0; if ( g_shell_parse_argv ( command, &argc, &argv, &error ) ) { argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); @@ -171,13 +169,13 @@ static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg, actual_size += 256; retv = g_realloc ( retv, ( actual_size ) * sizeof ( DmenuScriptEntry ) ); } - size_t buf_length = strlen(buffer)+1; - retv[( *length )].entry = g_memdup ( buffer, buf_length); - retv[( *length )].icon_name = NULL; - retv[( *length )].meta = NULL; - retv[(*length)].icon_fetch_uid = 0; - if ( buf_length > 0 && (read_length > (ssize_t)buf_length) ) { - dmenuscript_parse_entry_extras ( sw, &(retv[(*length)]), buffer+buf_length, read_length-buf_length); + size_t buf_length = strlen ( buffer ) + 1; + retv[( *length )].entry = g_memdup ( buffer, buf_length ); + retv[( *length )].icon_name = NULL; + retv[( *length )].meta = NULL; + retv[( *length )].icon_fetch_uid = 0; + if ( buf_length > 0 && ( read_length > (ssize_t) buf_length ) ) { + dmenuscript_parse_entry_extras ( sw, &( retv[( *length )] ), buffer + buf_length, read_length - buf_length ); } retv[( *length ) + 1].entry = NULL; ( *length )++; @@ -242,7 +240,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned { ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; ModeMode retv = MODE_EXIT; - DmenuScriptEntry *new_list = NULL; + DmenuScriptEntry *new_list = NULL; unsigned int new_length = 0; if ( ( mretv & MENU_NEXT ) ) { @@ -265,7 +263,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned // If a new list was generated, use that an loop around. if ( new_list != NULL ) { - for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ){ + for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) { g_free ( rmpd->cmd_list[i].entry ); g_free ( rmpd->cmd_list[i].icon_name ); g_free ( rmpd->cmd_list[i].meta ); @@ -283,7 +281,7 @@ static void script_mode_destroy ( Mode *sw ) { ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; if ( rmpd != NULL ) { - for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ){ + for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) { g_free ( rmpd->cmd_list[i].entry ); g_free ( rmpd->cmd_list[i].icon_name ); g_free ( rmpd->cmd_list[i].meta ); @@ -299,8 +297,12 @@ static void script_mode_destroy ( Mode *sw ) } static inline unsigned int get_index ( unsigned int length, int index ) { - if ( index >= 0 ) return index; - if ( ((unsigned int)-index) <= length ) return (length+index); + if ( index >= 0 ) { + return index; + } + if ( ( (unsigned int) -index ) <= length ) { + return length + index; + } // Out of range. return UINT_MAX; } @@ -330,20 +332,20 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_ static int script_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ) { ScriptModePrivateData *rmpd = sw->private_data; - int match = 1; + int match = 1; if ( tokens ) { - for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { - rofi_int_matcher *ftokens[2] = { tokens[j], NULL }; - int test = 0; - test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry ); - if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) { - test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta); - } + for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { + rofi_int_matcher *ftokens[2] = { tokens[j], NULL }; + int test = 0; + test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry ); + if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) { + test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta ); + } - if ( test == 0 ) { - match = 0; - } - } + if ( test == 0 ) { + match = 0; + } + } } return match; } @@ -356,7 +358,7 @@ static cairo_surface_t *script_get_icon ( const Mode *sw, unsigned int selected_ { ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw ); g_return_val_if_fail ( pd->cmd_list != NULL, NULL ); - DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); + DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); if ( dr->icon_name == NULL ) { return NULL; } |