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

autocomplete pathnames with spaces

This commit is contained in:
Jfreegman 2014-07-18 03:10:41 -04:00
parent f30dccf726
commit d4e41d6053

View File

@ -86,7 +86,6 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
const char *L = (char *) list; const char *L = (char *) list;
bool dir_search = false;
const char *endchrs = " "; const char *endchrs = " ";
char ubuf[MAX_STR_SIZE]; char ubuf[MAX_STR_SIZE];
@ -94,30 +93,33 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
if (wcs_to_mbs_buf(ubuf, ctx->line, sizeof(ubuf)) == -1) if (wcs_to_mbs_buf(ubuf, ctx->line, sizeof(ubuf)) == -1)
return -1; return -1;
bool dir_search = strncmp(ubuf, "/sendfile", strlen("/sendfile")) == 0;
/* isolate substring from space behind pos to pos */ /* isolate substring from space behind pos to pos */
char tmp[MAX_STR_SIZE]; char tmp[MAX_STR_SIZE];
snprintf(tmp, sizeof(tmp), "%s", ubuf); snprintf(tmp, sizeof(tmp), "%s", ubuf);
tmp[ctx->pos] = '\0'; tmp[ctx->pos] = '\0';
const char *s = strrchr(tmp, ' '); const char *s = dir_search ? strchr(tmp, '\"') : strrchr(tmp, ' ');
char *sub = malloc(strlen(ubuf) + 1); char *sub = malloc(strlen(ubuf) + 1);
if (sub == NULL) if (sub == NULL)
exit_toxic_err("failed in complete_line", FATALERR_MEMORY); exit_toxic_err("failed in complete_line", FATALERR_MEMORY);
if (!s) { if (!s && !dir_search) {
strcpy(sub, tmp); strcpy(sub, tmp);
if (sub[0] != '/') if (sub[0] != '/')
endchrs = ": "; endchrs = ": ";
} else { } else if (s) {
strcpy(sub, &s[1]); strcpy(sub, &s[1]);
if (strncmp(ubuf, "/sendfile", strlen("/sendfile")) == 0) { if (dir_search) {
dir_search = true;
int sub_len = strlen(sub); int sub_len = strlen(sub);
int si = char_rfind(sub, '/', sub_len); int si = char_rfind(sub, '/', sub_len);
memmove(sub, &sub[si + 1], sub_len - si);
if (si || *sub == '/')
memmove(sub, &sub[si + 1], sub_len - si);
} }
} }