391 print_resource_error(sn, path); |
391 print_resource_error(sn, path); |
392 break; |
392 break; |
393 } |
393 } |
394 |
394 |
395 // parameters |
395 // parameters |
396 void (*print_func)(DavResource*, CmdArgs *); |
396 void (*print_func)(DavResource*, char *, CmdArgs *); |
397 if(cmd_getoption(a, "list") || cmd_getoption(a, "extended")) { |
397 if(cmd_getoption(a, "list") || cmd_getoption(a, "extended")) { |
398 print_func = ls_print_list_elm; |
398 print_func = ls_print_list_elm; |
399 } else { |
399 } else { |
400 print_func = ls_print_elm; |
400 print_func = ls_print_elm; |
401 } |
401 } |
402 |
402 |
403 DavResource *child = ls->children; |
403 DavResource *child = ls->children; |
404 while(child) { |
404 while(child) { |
405 print_func(child, a); |
405 print_func(child, path, a); |
406 child = child->next; |
406 child = child->next; |
407 } |
407 } |
408 |
408 |
409 // leave loop |
409 // leave loop |
410 ret = 0; |
410 ret = 0; |
504 } |
504 } |
505 } |
505 } |
506 return str; |
506 return str; |
507 } |
507 } |
508 |
508 |
509 void ls_print_list_elm(DavResource *res, CmdArgs *a) { |
509 static char* ls_name(char *parent, char *path, int *len) { |
|
510 if(parent) { |
|
511 path += strlen(parent); |
|
512 } |
|
513 if(path[0] == '/') { |
|
514 path++; |
|
515 } |
|
516 int pathlen = strlen(path); |
|
517 if(path[pathlen-1] == '/') { |
|
518 pathlen--; |
|
519 } |
|
520 *len = pathlen; |
|
521 return path; |
|
522 } |
|
523 |
|
524 void ls_print_list_elm(DavResource *res, char *parent, CmdArgs *a) { |
510 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
525 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
511 int show_all = cmd_getoption(a, "all") ? 1 : 0; |
526 int show_all = cmd_getoption(a, "all") ? 1 : 0; |
512 if(res->name[0] == '.' && !show_all) { |
527 if(res->name[0] == '.' && !show_all) { |
513 return; |
528 return; |
514 } |
529 } |
554 type = ""; |
569 type = ""; |
555 } |
570 } |
556 |
571 |
557 char *date = ls_date_str(res->lastmodified); |
572 char *date = ls_date_str(res->lastmodified); |
558 char *size = ls_size_str(res); |
573 char *size = ls_size_str(res); |
559 char *name = recursive ? res->path+1 : res->name; |
574 int namelen = strlen(res->name); |
|
575 char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name; |
|
576 |
|
577 //char *name = recursive ? res->path+1 : res->name; |
560 printf( |
578 printf( |
561 "%s %*s %10s %12s %s\n", |
579 "%s %*s %10s %12s %.*s\n", |
562 flags, |
580 flags, |
563 type_width, type, |
581 type_width, type, |
564 size, |
582 size, |
565 date, |
583 date, |
|
584 namelen, |
566 name); |
585 name); |
567 free(date); |
586 free(date); |
568 free(size); |
587 free(size); |
569 |
588 |
570 if(recursive) { |
589 if(recursive) { |
571 DavResource *child = res->children; |
590 DavResource *child = res->children; |
572 while(child) { |
591 while(child) { |
573 //ls_print_list_elm(child, a); |
592 //ls_print_list_elm(child, a); |
574 if(child->name[0] != '.' || show_all) { |
593 if(child->name[0] != '.' || show_all) { |
575 ls_print_list_elm(child, a); |
594 ls_print_list_elm(child, parent, a); |
576 } |
595 } |
577 child = child->next; |
596 child = child->next; |
578 } |
597 } |
579 } |
598 } |
580 } |
599 } |
581 |
600 |
582 void ls_print_elm(DavResource *res, CmdArgs *a) { |
601 void ls_print_elm(DavResource *res, char *parent, CmdArgs *a) { |
583 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
602 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
584 int show_all = cmd_getoption(a, "all") ? 1 : 0; |
603 int show_all = cmd_getoption(a, "all") ? 1 : 0; |
585 if(res->name[0] == '.' && !show_all) { |
604 if(res->name[0] == '.' && !show_all) { |
586 return; |
605 return; |
587 } |
606 } |
588 |
607 |
589 char *name = recursive ? res->path+1 : res->name; |
608 int namelen = strlen(res->name); |
590 printf("%s\n", name); |
609 char *name = recursive ? ls_name(parent, res->path, &namelen) : res->name; |
|
610 printf("%.*s\n", namelen, name); |
591 if(recursive) { |
611 if(recursive) { |
592 DavResource *child = res->children; |
612 DavResource *child = res->children; |
593 while(child) { |
613 while(child) { |
594 ls_print_elm(child, a); |
614 ls_print_elm(child, parent, a); |
595 child = child->next; |
615 child = child->next; |
596 } |
616 } |
597 } |
617 } |
598 } |
618 } |
599 |
619 |