Thu, 28 Jun 2018 17:42:49 +0200
adjusts completion index, if options are specified
dav/main.c | file | annotate | diff | comparison | revisions | |
dav/main.h | file | annotate | diff | comparison | revisions |
--- a/dav/main.c Thu Jun 28 16:52:54 2018 +0200 +++ b/dav/main.c Thu Jun 28 17:42:49 2018 +0200 @@ -156,7 +156,28 @@ || !strcasecmp(cmd, "--version")) { fprintf(stderr, "dav %s\n", DAV_VERSION); } else if(!strcasecmp(cmd, "complete")) { - ret = shell_completion(args); + if(args->argc < 2) { + return 1; + } + char *index_str = args->argv[0]; + int64_t index = 0; + if(!util_strtoint(index_str, &index)) { + return 1; + } + if(args->argc + 2 != argc) { + // we have to fix the index + + for(int i=2;i<args->argc;i++) { + if(index == i-2) { + break; + } + if(strcmp(argv[i+2], args->argv[i])) { + index--; + } + } + } + + ret = shell_completion(args, index); } else { print_usage(argv[0]); } @@ -2011,14 +2032,8 @@ } -int shell_completion(CmdArgs *args) { - if(args->argc < 2) { - return 1; - } - - char *index_str = args->argv[0]; - int64_t index = 0; - if(!util_strtoint(index_str, &index)) { +int shell_completion(CmdArgs *args, int index) { + if(args->argc < 2 || args->argc < 3) { return 1; } @@ -2157,11 +2172,15 @@ ucx_buffer_putc(out, '/'); } printf("%.*s\n", (int)out->pos, out->space); + + ucx_buffer_free(out); } elm = elm->next; } + free(lspath); + dav_session_destroy(sn); } return 10;