summaryrefslogtreecommitdiff
path: root/src/gtkcompletionline.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gtkcompletionline.cc')
-rw-r--r--src/gtkcompletionline.cc25
1 files changed, 23 insertions, 2 deletions
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++) {
{