version 1.118, 2010/01/09 11:13:02 |
version 1.119, 2010/01/13 01:40:16 |
|
|
#define WHITESPACE " \t\r\n" |
#define WHITESPACE " \t\r\n" |
|
|
/* ls flags */ |
/* ls flags */ |
#define LS_LONG_VIEW 0x01 /* Full view ala ls -l */ |
#define LS_LONG_VIEW 0x0001 /* Full view ala ls -l */ |
#define LS_SHORT_VIEW 0x02 /* Single row view ala ls -1 */ |
#define LS_SHORT_VIEW 0x0002 /* Single row view ala ls -1 */ |
#define LS_NUMERIC_VIEW 0x04 /* Long view with numeric uid/gid */ |
#define LS_NUMERIC_VIEW 0x0004 /* Long view with numeric uid/gid */ |
#define LS_NAME_SORT 0x08 /* Sort by name (default) */ |
#define LS_NAME_SORT 0x0008 /* Sort by name (default) */ |
#define LS_TIME_SORT 0x10 /* Sort by mtime */ |
#define LS_TIME_SORT 0x0010 /* Sort by mtime */ |
#define LS_SIZE_SORT 0x20 /* Sort by file size */ |
#define LS_SIZE_SORT 0x0020 /* Sort by file size */ |
#define LS_REVERSE_SORT 0x40 /* Reverse sort order */ |
#define LS_REVERSE_SORT 0x0040 /* Reverse sort order */ |
#define LS_SHOW_ALL 0x80 /* Don't skip filenames starting with '.' */ |
#define LS_SHOW_ALL 0x0080 /* Don't skip filenames starting with '.' */ |
|
#define LS_SI_UNITS 0x0100 /* Display sizes as K, M, G, etc. */ |
|
|
#define VIEW_FLAGS (LS_LONG_VIEW|LS_SHORT_VIEW|LS_NUMERIC_VIEW) |
#define VIEW_FLAGS (LS_LONG_VIEW|LS_SHORT_VIEW|LS_NUMERIC_VIEW|LS_SI_UNITS) |
#define SORT_FLAGS (LS_NAME_SORT|LS_TIME_SORT|LS_SIZE_SORT) |
#define SORT_FLAGS (LS_NAME_SORT|LS_TIME_SORT|LS_SIZE_SORT) |
|
|
/* Commands for interactive mode */ |
/* Commands for interactive mode */ |
|
|
opterr = 0; |
opterr = 0; |
|
|
*lflag = LS_NAME_SORT; |
*lflag = LS_NAME_SORT; |
while ((ch = getopt(argc, argv, "1Saflnrt")) != -1) { |
while ((ch = getopt(argc, argv, "1Safhlnrt")) != -1) { |
switch (ch) { |
switch (ch) { |
case '1': |
case '1': |
*lflag &= ~VIEW_FLAGS; |
*lflag &= ~VIEW_FLAGS; |
|
|
case 'f': |
case 'f': |
*lflag &= ~SORT_FLAGS; |
*lflag &= ~SORT_FLAGS; |
break; |
break; |
|
case 'h': |
|
*lflag |= LS_SI_UNITS; |
|
break; |
case 'l': |
case 'l': |
*lflag &= ~VIEW_FLAGS; |
*lflag &= ~LS_SHORT_VIEW; |
*lflag |= LS_LONG_VIEW; |
*lflag |= LS_LONG_VIEW; |
break; |
break; |
case 'n': |
case 'n': |
*lflag &= ~VIEW_FLAGS; |
*lflag &= ~LS_SHORT_VIEW; |
*lflag |= LS_NUMERIC_VIEW|LS_LONG_VIEW; |
*lflag |= LS_NUMERIC_VIEW|LS_LONG_VIEW; |
break; |
break; |
case 'r': |
case 'r': |
|
|
xfree(tmp); |
xfree(tmp); |
|
|
if (lflag & LS_LONG_VIEW) { |
if (lflag & LS_LONG_VIEW) { |
if (lflag & LS_NUMERIC_VIEW) { |
if (lflag & (LS_NUMERIC_VIEW|LS_SI_UNITS)) { |
char *lname; |
char *lname; |
struct stat sb; |
struct stat sb; |
|
|
memset(&sb, 0, sizeof(sb)); |
memset(&sb, 0, sizeof(sb)); |
attrib_to_stat(&d[n]->a, &sb); |
attrib_to_stat(&d[n]->a, &sb); |
lname = ls_file(fname, &sb, 1); |
lname = ls_file(fname, &sb, 1, |
|
(lflag & LS_SI_UNITS)); |
printf("%s\n", lname); |
printf("%s\n", lname); |
xfree(lname); |
xfree(lname); |
} else |
} else |
|
|
a = do_lstat(conn, g.gl_pathv[i], 1); |
a = do_lstat(conn, g.gl_pathv[i], 1); |
if (a != NULL) |
if (a != NULL) |
attrib_to_stat(a, &sb); |
attrib_to_stat(a, &sb); |
lname = ls_file(fname, &sb, 1); |
lname = ls_file(fname, &sb, 1, (lflag & LS_SI_UNITS)); |
printf("%s\n", lname); |
printf("%s\n", lname); |
xfree(lname); |
xfree(lname); |
} else { |
} else { |