summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--sftp-int.c79
2 files changed, 69 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 89ef50273..ca7125bf8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,10 @@
31 - mouring@cvs.openbsd.org 2003/05/15 03:39:07 31 - mouring@cvs.openbsd.org 2003/05/15 03:39:07
32 [sftp-int.c] 32 [sftp-int.c]
33 Make put/get (globed and nonglobed) code more consistant. OK djm@ 33 Make put/get (globed and nonglobed) code more consistant. OK djm@
34 - mouring@cvs.openbsd.org 2003/05/15 03:43:59
35 [sftp-int.c]
36 Teach ls how to display multiple column display and allow users
37 to return to single column format via 'ls -1'. OK @djm
34 - (djm) Always parse UsePAM 38 - (djm) Always parse UsePAM
35 - (djm) Configure glue for DNS support (code doesn't work in portable yet) 39 - (djm) Configure glue for DNS support (code doesn't work in portable yet)
36 - (djm) Import getrrsetbyname() function from OpenBSD libc (for DNS support) 40 - (djm) Import getrrsetbyname() function from OpenBSD libc (for DNS support)
@@ -1511,4 +1515,4 @@
1511 save auth method before monitor_reset_key_state(); bugzilla bug #284; 1515 save auth method before monitor_reset_key_state(); bugzilla bug #284;
1512 ok provos@ 1516 ok provos@
1513 1517
1514$Id: ChangeLog,v 1.2713 2003/05/15 03:48:59 djm Exp $ 1518$Id: ChangeLog,v 1.2714 2003/05/15 03:49:21 djm Exp $
diff --git a/sftp-int.c b/sftp-int.c
index 25879baf1..f2d3f9468 100644
--- a/sftp-int.c
+++ b/sftp-int.c
@@ -25,7 +25,7 @@
25/* XXX: recursive operations */ 25/* XXX: recursive operations */
26 26
27#include "includes.h" 27#include "includes.h"
28RCSID("$OpenBSD: sftp-int.c,v 1.59 2003/05/15 03:39:07 mouring Exp $"); 28RCSID("$OpenBSD: sftp-int.c,v 1.60 2003/05/15 03:43:59 mouring Exp $");
29 29
30#include "buffer.h" 30#include "buffer.h"
31#include "xmalloc.h" 31#include "xmalloc.h"
@@ -53,6 +53,10 @@ int showprogress = 1;
53/* Seperators for interactive commands */ 53/* Seperators for interactive commands */
54#define WHITESPACE " \t\r\n" 54#define WHITESPACE " \t\r\n"
55 55
56/* Define what type of ls view (0 - multi-column) */
57#define LONG_VIEW 1 /* Full view ala ls -l */
58#define SHORT_VIEW 2 /* Single row view ala ls -1 */
59
56/* Commands for interactive mode */ 60/* Commands for interactive mode */
57#define I_CHDIR 1 61#define I_CHDIR 1
58#define I_CHGRP 2 62#define I_CHGRP 2
@@ -307,7 +311,10 @@ parse_ls_flags(const char **cpp, int *lflag)
307 for(; strchr(WHITESPACE, *cp) == NULL; cp++) { 311 for(; strchr(WHITESPACE, *cp) == NULL; cp++) {
308 switch (*cp) { 312 switch (*cp) {
309 case 'l': 313 case 'l':
310 *lflag = 1; 314 *lflag = LONG_VIEW;
315 break;
316 case '1':
317 *lflag = SHORT_VIEW;
311 break; 318 break;
312 default: 319 default:
313 error("Invalid flag -%c", *cp); 320 error("Invalid flag -%c", *cp);
@@ -558,15 +565,26 @@ sdirent_comp(const void *aa, const void *bb)
558static int 565static int
559do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) 566do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
560{ 567{
561 int n; 568 int n, c = 1, colspace = 0, columns = 1;
562 SFTP_DIRENT **d; 569 SFTP_DIRENT **d;
563 570
564 if ((n = do_readdir(conn, path, &d)) != 0) 571 if ((n = do_readdir(conn, path, &d)) != 0)
565 return (n); 572 return (n);
566 573
567 /* Count entries for sort */ 574 if (!(lflag & SHORT_VIEW)) {
568 for (n = 0; d[n] != NULL; n++) 575 int m = 0, width = 80;
569 ; 576 struct winsize ws;
577
578 /* Count entries for sort and find longest filename */
579 for (n = 0; d[n] != NULL; n++)
580 m = MAX(m, strlen(d[n]->filename));
581
582 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
583 width = ws.ws_col;
584
585 columns = width / (m + 2);
586 colspace = width / columns;
587 }
570 588
571 qsort(d, n, sizeof(*d), sdirent_comp); 589 qsort(d, n, sizeof(*d), sdirent_comp);
572 590
@@ -577,7 +595,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
577 fname = path_strip(tmp, strip_path); 595 fname = path_strip(tmp, strip_path);
578 xfree(tmp); 596 xfree(tmp);
579 597
580 if (lflag) { 598 if (lflag & LONG_VIEW) {
581 char *lname; 599 char *lname;
582 struct stat sb; 600 struct stat sb;
583 601
@@ -587,13 +605,20 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
587 printf("%s\n", lname); 605 printf("%s\n", lname);
588 xfree(lname); 606 xfree(lname);
589 } else { 607 } else {
590 /* XXX - multicolumn display would be nice here */ 608 printf("%-*s", colspace, fname);
591 printf("%s\n", fname); 609 if (c >= columns) {
610 printf("\n");
611 c = 1;
612 } else
613 c++;
592 } 614 }
593 615
594 xfree(fname); 616 xfree(fname);
595 } 617 }
596 618
619 if (!(lflag & LONG_VIEW) && (c != 1))
620 printf("\n");
621
597 free_sftp_dirents(d); 622 free_sftp_dirents(d);
598 return (0); 623 return (0);
599} 624}
@@ -604,9 +629,8 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
604 int lflag) 629 int lflag)
605{ 630{
606 glob_t g; 631 glob_t g;
607 int i; 632 int i, c = 1, colspace = 0, columns = 1;
608 Attrib *a; 633 Attrib *a;
609 struct stat sb;
610 634
611 memset(&g, 0, sizeof(g)); 635 memset(&g, 0, sizeof(g));
612 636
@@ -633,12 +657,30 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
633 } 657 }
634 } 658 }
635 659
660 if (!(lflag & SHORT_VIEW)) {
661 int m = 0, width = 80;
662 struct winsize ws;
663
664 /* Count entries for sort and find longest filename */
665 for (i = 0; g.gl_pathv[i]; i++)
666 m = MAX(m, strlen(g.gl_pathv[i]));
667
668 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
669 width = ws.ws_col;
670
671 columns = width / (m + 2);
672 colspace = width / columns;
673 }
674
636 for (i = 0; g.gl_pathv[i]; i++) { 675 for (i = 0; g.gl_pathv[i]; i++) {
637 char *fname, *lname; 676 char *fname;
638 677
639 fname = path_strip(g.gl_pathv[i], strip_path); 678 fname = path_strip(g.gl_pathv[i], strip_path);
640 679
641 if (lflag) { 680 if (lflag & LONG_VIEW) {
681 char *lname;
682 struct stat sb;
683
642 /* 684 /*
643 * XXX: this is slow - 1 roundtrip per path 685 * XXX: this is slow - 1 roundtrip per path
644 * A solution to this is to fork glob() and 686 * A solution to this is to fork glob() and
@@ -654,12 +696,19 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
654 printf("%s\n", lname); 696 printf("%s\n", lname);
655 xfree(lname); 697 xfree(lname);
656 } else { 698 } else {
657 /* XXX - multicolumn display would be nice here */ 699 printf("%-*s", colspace, fname);
658 printf("%s\n", fname); 700 if (c >= columns) {
701 printf("\n");
702 c = 1;
703 } else
704 c++;
659 } 705 }
660 xfree(fname); 706 xfree(fname);
661 } 707 }
662 708
709 if (!(lflag & LONG_VIEW) && (c != 1))
710 printf("\n");
711
663 if (g.gl_pathc) 712 if (g.gl_pathc)
664 globfree(&g); 713 globfree(&g);
665 714