diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-06-07 09:02:03 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-06-07 09:02:03 +0200 |
commit | 0b84d63959fb0e9eb4409412c0d132eb940f0be5 (patch) | |
tree | 600e12675683b7867bdd5dc1ca6d135f19ebea53 /source/dialogs | |
parent | 72d6c2087629379926550331a0f8d592e9c6204d (diff) | |
parent | 87461c7ec327da9f3cd9e4e443bbb5f4930d8241 (diff) |
Merge remote-tracking branch 'origin/master' into highlight_match
Diffstat (limited to 'source/dialogs')
-rw-r--r-- | source/dialogs/drun.c | 104 | ||||
-rw-r--r-- | source/dialogs/ssh.c | 2 |
2 files changed, 64 insertions, 42 deletions
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index f0ffd551..feec11c6 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -32,6 +32,7 @@ #include <limits.h> #include <signal.h> #include <sys/types.h> +#include <sys/stat.h> #include <dirent.h> #include <strings.h> #include <string.h> @@ -197,27 +198,64 @@ static void read_desktop_file ( DRunModePrivateData *pd, char *path, const char /** * Internal spider used to get list of executables. */ -static void get_apps_dir ( DRunModePrivateData *pd, const char *bp ) +static void walk_dir ( DRunModePrivateData *pd, const char *dirname ) { - DIR *dir = opendir ( bp ); + DIR *dir; - if ( dir != NULL ) { - struct dirent *dent; + dir = opendir ( dirname ); + if ( dir == NULL ) { + return; + } - while ( ( dent = readdir ( dir ) ) != NULL ) { - if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) { - continue; - } - // Skip dot files. - if ( dent->d_name[0] == '.' ) { - continue; + struct dirent *file; + gchar *filename = NULL; + struct stat st; + while ( ( file = readdir ( dir ) ) != NULL ) { + if ( file->d_name[0] == '.' ) { + continue; + } + + switch ( file->d_type ) + { + case DT_LNK: + case DT_REG: + case DT_DIR: + case DT_UNKNOWN: + filename = g_build_filename ( dirname, file->d_name, NULL ); + break; + default: + continue; + } + + // On a link, or if FS does not support providing this information + // Fallback to stat method. + if ( file->d_type == DT_LNK || file->d_type == DT_UNKNOWN ) { + file->d_type = DT_UNKNOWN; + if ( stat ( filename, &st ) == 0 ) { + if ( S_ISDIR ( st.st_mode ) ) { + file->d_type = DT_DIR; + } + else if ( S_ISREG ( st.st_mode ) ) { + file->d_type = DT_REG; + } } - gchar *path = g_build_filename ( bp, dent->d_name, NULL ); - read_desktop_file ( pd, path, dent->d_name ); } - closedir ( dir ); + switch ( file->d_type ) + { + case DT_REG: + read_desktop_file ( pd, filename, file->d_name ); + filename = NULL; + break; + case DT_DIR: + walk_dir ( pd, filename ); + break; + default: + break; + } + g_free ( filename ); } + closedir ( dir ); } /** * @param entry The command entry to remove from history @@ -232,6 +270,7 @@ static void delete_entry_history ( const DRunModeEntry *entry ) g_free ( path ); } + static void get_apps_history ( DRunModePrivateData *pd ) { unsigned int length = 0; @@ -246,38 +285,21 @@ static void get_apps_history ( DRunModePrivateData *pd ) g_free ( retv ); pd->history_length = pd->cmd_list_length; } + static void get_apps ( DRunModePrivateData *pd ) { get_apps_history ( pd ); - const char * const * dr = g_get_system_data_dirs (); - const char * const * iter = dr; - while ( iter != NULL && *iter != NULL && **iter != '\0' ) { - gboolean skip = FALSE; - for ( size_t i = 0; !skip && dr[i] != ( *iter ); i++ ) { - skip = ( g_strcmp0 ( *iter, dr[i] ) == 0 ); - } - if ( skip ) { - iter++; - continue; - } - gchar *bp = g_build_filename ( *iter, "applications", NULL ); - get_apps_dir ( pd, bp ); - g_free ( bp ); - iter++; - } - const char *d = g_get_user_data_dir (); - for ( size_t i = 0; dr && dr[i] != NULL; i++ ) { - if ( g_strcmp0 ( d, dr[i] ) == 0 ) { - // Done this already, no need to repeat. - return; - } - } - if ( d ) { - gchar *bp = g_build_filename ( d, "applications", NULL ); - get_apps_dir ( pd, bp ); - g_free ( bp ); + gchar *dir; + const gchar * const * sys = g_get_system_data_dirs (); + for (; *sys != NULL; ++sys ) { + dir = g_build_filename ( *sys, "applications", NULL ); + walk_dir ( pd, dir ); + g_free ( dir ); } + dir = g_build_filename ( g_get_user_data_dir (), "applications", NULL ); + walk_dir ( pd, dir ); + g_free ( dir ); } static int drun_mode_init ( Mode *sw ) diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 331e5431..9cc75543 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length ) // Reading one line per time. while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { // Evaluate one line. - unsigned int index = 0, ti = 0; + unsigned int index = 0, ti = 0; char *token = buffer; // Tokenize it. |