From 00686185734e99d9b41d1309f51f8e714490bad6 Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Tue, 21 Jan 2014 10:35:59 +0100 Subject: [PATCH] cleanup --- source/simpleswitcher.c | 59 ++++++++++------------------------------- source/ssh-dialog.c | 9 ++++++- 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/source/simpleswitcher.c b/source/simpleswitcher.c index 4ed65442..78b9aeff 100644 --- a/source/simpleswitcher.c +++ b/source/simpleswitcher.c @@ -354,10 +354,6 @@ void winlist_free( winlist *l ) free( l->data ); free( l ); } -void winlist_empty_2d( winlist *l ) -{ - while ( l->len > 0 ) winlist_free( l->data[--( l->len )] ); -} int winlist_find( winlist *l, Window w ) { // iterate backwards. theory is: windows most often accessed will be @@ -369,23 +365,6 @@ int winlist_find( winlist *l, Window w ) return -1; } -int winlist_forget( winlist *l, Window w ) -{ - int i, j; - - for ( i = 0, j = 0; i < l->len; i++, j++ ) { - l->array[j] = l->array[i]; - l->data[j] = l->data[i]; - - if ( l->array[i] == w ) { - free( l->data[i] ); - j--; - } - } - - l->len -= ( i-j ); - return j != i ?1:0; -} #define CLIENTTITLE 100 #define CLIENTCLASS 50 @@ -1273,7 +1252,17 @@ void help() } } +inline int program_end() +{ + winlist_free( cache_xattr ); + winlist_free( cache_client ); +#ifdef I3 + if ( i3_socket_path != NULL ) free( i3_socket_path ); + +#endif + return EXIT_SUCCESS; +} int main( int argc, char *argv[] ) @@ -1357,32 +1346,17 @@ int main( int argc, char *argv[] ) // flags to run immediately and exit if ( find_arg( ac, av, "-now" ) >= 0 ) { run_switcher( NOFORK, WINDOW_SWITCHER ); -#ifdef I3 - - if ( i3_socket_path != NULL ) free( i3_socket_path ); - -#endif - exit( EXIT_SUCCESS ); + return program_end(); } if ( find_arg( ac, av, "-rnow" ) >= 0 ) { run_switcher( NOFORK, RUN_DIALOG ); -#ifdef I3 - - if ( i3_socket_path != NULL ) free( i3_socket_path ); - -#endif - exit( EXIT_SUCCESS ); + return program_end(); } if ( find_arg( ac, av, "-snow" ) >= 0 ) { run_switcher( NOFORK, SSH_DIALOG ); -#ifdef I3 - - if ( i3_socket_path != NULL ) free( i3_socket_path ); - -#endif - exit( EXIT_SUCCESS ); + return program_end(); } // in background mode from here on @@ -1413,10 +1387,5 @@ int main( int argc, char *argv[] ) if ( ev.type == KeyPress ) handle_keypress( &ev ); } -#ifdef I3 - - if ( i3_socket_path != NULL ) free( i3_socket_path ); - -#endif - return EXIT_SUCCESS; + return program_end(); } diff --git a/source/ssh-dialog.c b/source/ssh-dialog.c index eb6433ea..f8ca8d20 100644 --- a/source/ssh-dialog.c +++ b/source/ssh-dialog.c @@ -184,11 +184,18 @@ static char ** get_ssh ( ) for ( stop=start; isalnum( buffer[stop] ); stop++ ); + int found = 0; + // This is a nice little penalty, but doable? time will tell. + // given num_favorites is max 25. + for ( int j = 0; found == 0 && j < num_favorites; j++ ) { + if ( strncasecmp( &buffer[start], retv[j],stop-start ) == 0 ) found = 1; + } + if ( found == 1 ) continue; + retv = realloc( retv, ( index+2 )*sizeof( char* ) ); retv[index] = strndup( &buffer[start], stop-start ); retv[index+1] = NULL; index++; - num_favorites++; } }