diff -r c89633916e36 -r 0edfb4c0e7f8 dav/main.c --- a/dav/main.c Thu Aug 03 11:43:04 2017 +0200 +++ b/dav/main.c Thu Aug 03 12:31:17 2017 +0200 @@ -393,7 +393,7 @@ } // parameters - void (*print_func)(DavResource*, CmdArgs *); + void (*print_func)(DavResource*, char *, CmdArgs *); if(cmd_getoption(a, "list") || cmd_getoption(a, "extended")) { print_func = ls_print_list_elm; } else { @@ -402,7 +402,7 @@ DavResource *child = ls->children; while(child) { - print_func(child, a); + print_func(child, path, a); child = child->next; } @@ -506,7 +506,22 @@ return str; } -void ls_print_list_elm(DavResource *res, CmdArgs *a) { +static char* ls_name(char *parent, char *path, int *len) { + if(parent) { + path += strlen(parent); + } + if(path[0] == '/') { + path++; + } + int pathlen = strlen(path); + if(path[pathlen-1] == '/') { + pathlen--; + } + *len = pathlen; + return path; +} + +void ls_print_list_elm(DavResource *res, char *parent, CmdArgs *a) { int recursive = cmd_getoption(a, "recursive") ? 1 : 0; int show_all = cmd_getoption(a, "all") ? 1 : 0; if(res->name[0] == '.' && !show_all) { @@ -556,13 +571,17 @@ char *date = ls_date_str(res->lastmodified); char *size = ls_size_str(res); - char *name = recursive ? res->path+1 : res->name; + int namelen = strlen(res->name); + char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name; + + //char *name = recursive ? res->path+1 : res->name; printf( - "%s %*s %10s %12s %s\n", + "%s %*s %10s %12s %.*s\n", flags, type_width, type, size, date, + namelen, name); free(date); free(size); @@ -572,26 +591,27 @@ while(child) { //ls_print_list_elm(child, a); if(child->name[0] != '.' || show_all) { - ls_print_list_elm(child, a); + ls_print_list_elm(child, parent, a); } child = child->next; } } } -void ls_print_elm(DavResource *res, CmdArgs *a) { +void ls_print_elm(DavResource *res, char *parent, CmdArgs *a) { int recursive = cmd_getoption(a, "recursive") ? 1 : 0; int show_all = cmd_getoption(a, "all") ? 1 : 0; if(res->name[0] == '.' && !show_all) { return; } - char *name = recursive ? res->path+1 : res->name; - printf("%s\n", name); + int namelen = strlen(res->name); + char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name; + printf("%.*s\n", namelen, name); if(recursive) { DavResource *child = res->children; while(child) { - ls_print_elm(child, a); + ls_print_elm(child, parent, a); child = child->next; } }