summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--sftp.c58
2 files changed, 33 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 657147779..0fe2f77dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,9 @@
27 - djm@cvs.openbsd.org 2004/06/21 22:04:50 27 - djm@cvs.openbsd.org 2004/06/21 22:04:50
28 [sftp.c] 28 [sftp.c]
29 introduce sorting for ls, same options as /bin/ls; ok markus@ 29 introduce sorting for ls, same options as /bin/ls; ok markus@
30 - djm@cvs.openbsd.org 2004/06/21 22:30:45
31 [sftp.c]
32 prefix ls option flags with LS_
30 33
3120040620 3420040620
32 - (tim) [configure.ac Makefile.in] Only change TEST_SHELL on broken platforms. 35 - (tim) [configure.ac Makefile.in] Only change TEST_SHELL on broken platforms.
@@ -1349,4 +1352,4 @@
1349 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 1352 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
1350 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 1353 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
1351 1354
1352$Id: ChangeLog,v 1.3424 2004/06/22 03:06:45 dtucker Exp $ 1355$Id: ChangeLog,v 1.3425 2004/06/22 03:07:58 dtucker Exp $
diff --git a/sftp.c b/sftp.c
index 91e9cfd81..37adb0286 100644
--- a/sftp.c
+++ b/sftp.c
@@ -16,7 +16,7 @@
16 16
17#include "includes.h" 17#include "includes.h"
18 18
19RCSID("$OpenBSD: sftp.c,v 1.52 2004/06/21 22:04:50 djm Exp $"); 19RCSID("$OpenBSD: sftp.c,v 1.53 2004/06/21 22:30:45 djm Exp $");
20 20
21#include "buffer.h" 21#include "buffer.h"
22#include "xmalloc.h" 22#include "xmalloc.h"
@@ -65,16 +65,16 @@ char *__progname;
65#define WHITESPACE " \t\r\n" 65#define WHITESPACE " \t\r\n"
66 66
67/* ls flags */ 67/* ls flags */
68#define LONG_VIEW 0x01 /* Full view ala ls -l */ 68#define LS_LONG_VIEW 0x01 /* Full view ala ls -l */
69#define SHORT_VIEW 0x02 /* Single row view ala ls -1 */ 69#define LS_SHORT_VIEW 0x02 /* Single row view ala ls -1 */
70#define NUMERIC_VIEW 0x04 /* Long view with numeric uid/gid */ 70#define LS_NUMERIC_VIEW 0x04 /* Long view with numeric uid/gid */
71#define NAME_SORT 0x08 /* Sort by name (default) */ 71#define LS_NAME_SORT 0x08 /* Sort by name (default) */
72#define TIME_SORT 0x10 /* Sort by mtime */ 72#define LS_TIME_SORT 0x10 /* Sort by mtime */
73#define SIZE_SORT 0x20 /* Sort by file size */ 73#define LS_SIZE_SORT 0x20 /* Sort by file size */
74#define REVERSE_SORT 0x40 /* Reverse sort order */ 74#define LS_REVERSE_SORT 0x40 /* Reverse sort order */
75 75
76#define VIEW_FLAGS (LONG_VIEW|SHORT_VIEW|NUMERIC_VIEW) 76#define VIEW_FLAGS (LS_LONG_VIEW|LS_SHORT_VIEW|LS_NUMERIC_VIEW)
77#define SORT_FLAGS (NAME_SORT|TIME_SORT|SIZE_SORT) 77#define SORT_FLAGS (LS_NAME_SORT|LS_TIME_SORT|LS_SIZE_SORT)
78 78
79/* Commands for interactive mode */ 79/* Commands for interactive mode */
80#define I_CHDIR 1 80#define I_CHDIR 1
@@ -346,7 +346,7 @@ parse_ls_flags(const char **cpp, int *lflag)
346 const char *cp = *cpp; 346 const char *cp = *cpp;
347 347
348 /* Defaults */ 348 /* Defaults */
349 *lflag = NAME_SORT; 349 *lflag = LS_NAME_SORT;
350 350
351 /* Check for flags */ 351 /* Check for flags */
352 if (cp++[0] == '-') { 352 if (cp++[0] == '-') {
@@ -354,26 +354,26 @@ parse_ls_flags(const char **cpp, int *lflag)
354 switch (*cp) { 354 switch (*cp) {
355 case 'l': 355 case 'l':
356 *lflag &= ~VIEW_FLAGS; 356 *lflag &= ~VIEW_FLAGS;
357 *lflag |= LONG_VIEW; 357 *lflag |= LS_LONG_VIEW;
358 break; 358 break;
359 case '1': 359 case '1':
360 *lflag &= ~VIEW_FLAGS; 360 *lflag &= ~VIEW_FLAGS;
361 *lflag |= SHORT_VIEW; 361 *lflag |= LS_SHORT_VIEW;
362 break; 362 break;
363 case 'n': 363 case 'n':
364 *lflag &= ~VIEW_FLAGS; 364 *lflag &= ~VIEW_FLAGS;
365 *lflag |= NUMERIC_VIEW|LONG_VIEW; 365 *lflag |= LS_NUMERIC_VIEW|LS_LONG_VIEW;
366 break; 366 break;
367 case 'S': 367 case 'S':
368 *lflag &= ~SORT_FLAGS; 368 *lflag &= ~SORT_FLAGS;
369 *lflag |= SIZE_SORT; 369 *lflag |= LS_SIZE_SORT;
370 break; 370 break;
371 case 't': 371 case 't':
372 *lflag &= ~SORT_FLAGS; 372 *lflag &= ~SORT_FLAGS;
373 *lflag |= TIME_SORT; 373 *lflag |= LS_TIME_SORT;
374 break; 374 break;
375 case 'r': 375 case 'r':
376 *lflag |= REVERSE_SORT; 376 *lflag |= LS_REVERSE_SORT;
377 break; 377 break;
378 case 'f': 378 case 'f':
379 *lflag &= ~SORT_FLAGS; 379 *lflag &= ~SORT_FLAGS;
@@ -637,14 +637,14 @@ sdirent_comp(const void *aa, const void *bb)
637{ 637{
638 SFTP_DIRENT *a = *(SFTP_DIRENT **)aa; 638 SFTP_DIRENT *a = *(SFTP_DIRENT **)aa;
639 SFTP_DIRENT *b = *(SFTP_DIRENT **)bb; 639 SFTP_DIRENT *b = *(SFTP_DIRENT **)bb;
640 int rmul = sort_flag & REVERSE_SORT ? -1 : 1; 640 int rmul = sort_flag & LS_REVERSE_SORT ? -1 : 1;
641 641
642#define NCMP(a,b) (a == b ? 0 : (a < b ? 1 : -1)) 642#define NCMP(a,b) (a == b ? 0 : (a < b ? 1 : -1))
643 if (sort_flag & NAME_SORT) 643 if (sort_flag & LS_NAME_SORT)
644 return (rmul * strcmp(a->filename, b->filename)); 644 return (rmul * strcmp(a->filename, b->filename));
645 else if (sort_flag & TIME_SORT) 645 else if (sort_flag & LS_TIME_SORT)
646 return (rmul * NCMP(a->a.mtime, b->a.mtime)); 646 return (rmul * NCMP(a->a.mtime, b->a.mtime));
647 else if (sort_flag & SIZE_SORT) 647 else if (sort_flag & LS_SIZE_SORT)
648 return (rmul * NCMP(a->a.size, b->a.size)); 648 return (rmul * NCMP(a->a.size, b->a.size));
649 649
650 fatal("Unknown ls sort type"); 650 fatal("Unknown ls sort type");
@@ -660,7 +660,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
660 if ((n = do_readdir(conn, path, &d)) != 0) 660 if ((n = do_readdir(conn, path, &d)) != 0)
661 return (n); 661 return (n);
662 662
663 if (!(lflag & SHORT_VIEW)) { 663 if (!(lflag & LS_SHORT_VIEW)) {
664 int m = 0, width = 80; 664 int m = 0, width = 80;
665 struct winsize ws; 665 struct winsize ws;
666 char *tmp; 666 char *tmp;
@@ -684,7 +684,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
684 } 684 }
685 685
686 if (lflag & SORT_FLAGS) { 686 if (lflag & SORT_FLAGS) {
687 sort_flag = lflag & (SORT_FLAGS|REVERSE_SORT); 687 sort_flag = lflag & (SORT_FLAGS|LS_REVERSE_SORT);
688 qsort(d, n, sizeof(*d), sdirent_comp); 688 qsort(d, n, sizeof(*d), sdirent_comp);
689 } 689 }
690 690
@@ -695,8 +695,8 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
695 fname = path_strip(tmp, strip_path); 695 fname = path_strip(tmp, strip_path);
696 xfree(tmp); 696 xfree(tmp);
697 697
698 if (lflag & LONG_VIEW) { 698 if (lflag & LS_LONG_VIEW) {
699 if (lflag & NUMERIC_VIEW) { 699 if (lflag & LS_NUMERIC_VIEW) {
700 char *lname; 700 char *lname;
701 struct stat sb; 701 struct stat sb;
702 702
@@ -719,7 +719,7 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
719 xfree(fname); 719 xfree(fname);
720 } 720 }
721 721
722 if (!(lflag & LONG_VIEW) && (c != 1)) 722 if (!(lflag & LS_LONG_VIEW) && (c != 1))
723 printf("\n"); 723 printf("\n");
724 724
725 free_sftp_dirents(d); 725 free_sftp_dirents(d);
@@ -763,7 +763,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
763 } 763 }
764 } 764 }
765 765
766 if (!(lflag & SHORT_VIEW)) { 766 if (!(lflag & LS_SHORT_VIEW)) {
767 int m = 0, width = 80; 767 int m = 0, width = 80;
768 struct winsize ws; 768 struct winsize ws;
769 769
@@ -784,7 +784,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
784 784
785 fname = path_strip(g.gl_pathv[i], strip_path); 785 fname = path_strip(g.gl_pathv[i], strip_path);
786 786
787 if (lflag & LONG_VIEW) { 787 if (lflag & LS_LONG_VIEW) {
788 char *lname; 788 char *lname;
789 struct stat sb; 789 struct stat sb;
790 790
@@ -813,7 +813,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
813 xfree(fname); 813 xfree(fname);
814 } 814 }
815 815
816 if (!(lflag & LONG_VIEW) && (c != 1)) 816 if (!(lflag & LS_LONG_VIEW) && (c != 1))
817 printf("\n"); 817 printf("\n");
818 818
819 out: 819 out: