From 7b63dc42973f07f58890612f63fbeb38b5781c7a Mon Sep 17 00:00:00 2001 From: Alexandre De Dommelin Date: Sun, 12 Mar 2017 15:49:46 -0700 Subject: debian-changes-0.9.2-2.1 Gbp-Pq: Name debian-changes-0.9.2-2.1 --- src/gtkcompletionline.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gtkcompletionline.cc b/src/gtkcompletionline.cc index 99fdfcf..90897f7 100644 --- a/src/gtkcompletionline.cc +++ b/src/gtkcompletionline.cc @@ -374,6 +374,27 @@ select_executables_only(const struct dirent* dent) return 0; } +int my_alphasort(const struct dirent** a, const struct dirent** b) { + const char* s1 = (*a)->d_name; + const char* s2 = (*b)->d_name; + + int l1 = strlen(s1); + int l2 = strlen(s2); + int result = strcmp(s1, s2); + + if (result == 0) return 0; + + if (l1 < l2) { + int res2 = strncmp(s1, s2, l1); + if (res2 == 0) return -1; + } else { + int res2 = strncmp(s1, s2, l2); + if (res2 == 0) return 1; + } + + return result; +} + static void generate_execs() { @@ -381,7 +402,7 @@ generate_execs() for (StrSet::iterator i = path.begin(); i != path.end(); i++) { struct dirent **eps; - int n = scandir(i->c_str(), &eps, select_executables_only, alphasort); + int n = scandir(i->c_str(), &eps, select_executables_only, my_alphasort); if (n >= 0) { for (int j = 0; j < n; j++) { execs.insert(eps[j]->d_name); @@ -481,7 +502,7 @@ generate_dirlist(const char *what) dirlist.clear(); struct dirent **eps; prefix = filename; - n = scandir(dest.c_str(), &eps, select_executables_only, alphasort); + n = scandir(dest.c_str(), &eps, select_executables_only, my_alphasort); if (n >= 0) { for (int j = 0; j < n; j++) { { -- cgit v1.2.3