1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 21:33:02 +01:00

sort directories and skip special symbols for path autocomplete

This commit is contained in:
Jfreegman 2014-07-23 18:34:32 -04:00
parent 8660047ec1
commit 8d8df585ad
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
3 changed files with 8 additions and 5 deletions

View File

@ -273,7 +273,8 @@ int dir_match(ToxWindow *self, Tox *m, wchar_t *line)
int dircount = 0;
while ((entry = readdir(dp)) && dircount < MAX_DIRS) {
if (strncmp(entry->d_name, b_name, b_name_len) == 0) {
if (strncmp(entry->d_name, b_name, b_name_len) == 0
&& strcmp(".", entry->d_name) && strcmp("..", entry->d_name)) {
snprintf(dirnames[dircount], sizeof(dirnames[dircount]), "%s", entry->d_name);
++dircount;
}
@ -282,8 +283,10 @@ int dir_match(ToxWindow *self, Tox *m, wchar_t *line)
if (dircount == 0)
return -1;
if (dircount > 1)
if (dircount > 1) {
qsort(dirnames, dircount, NAME_MAX, qsort_strcasecmp_hlpr);
print_matches(self, m, dirnames, dircount, NAME_MAX);
}
return complete_line(self, dirnames, dircount, NAME_MAX);
}

View File

@ -143,9 +143,9 @@ int wcs_to_mbs_buf(char *buf, const wchar_t *string, size_t n)
}
/* case-insensitive string compare function for use with qsort */
int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2)
int qsort_strcasecmp_hlpr(const void *str1, const void *str2)
{
return strcasecmp((const char *) nick1, (const char *) nick2);
return strcasecmp((const char *) str1, (const char *) str2);
}
/* Returns 1 if nick is valid, 0 if not. A valid toxic nick:

View File

@ -70,7 +70,7 @@ int timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime);
void alert_window(ToxWindow *self, int type, bool is_beep);
/* case-insensitive string compare function for use with qsort */
int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2);
int qsort_strcasecmp_hlpr(const void *str1, const void *str2);
/* Returns 1 if nick is valid, 0 if not. A valid toxic nick:
- cannot be empty