summaryrefslogtreecommitdiff
path: root/src/ls.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-07-06 21:23:42 +0000
committerJim Meyering <jim@meyering.net>1997-07-06 21:23:42 +0000
commitd0caad54ae952111f792ec95897e36f76049cb06 (patch)
tree44b5cedec9d616451e462ff5cff6ad69034a2c1c /src/ls.c
parentf873ad6e6c379efce22e3342aa1974db30365c9d (diff)
downloadcoreutils-d0caad54ae952111f792ec95897e36f76049cb06.tar.xz
Add new option: --sort=version (-v).
Diffstat (limited to 'src/ls.c')
-rw-r--r--src/ls.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/ls.c b/src/ls.c
index 86973875d..02534c259 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -68,6 +68,7 @@
#include "error.h"
#include "argmatch.h"
#include "xstrtol.h"
+#include "strverscmp.h"
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
@@ -175,6 +176,10 @@ static int compare_extension __P ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_extension __P ((const struct fileinfo *file2,
const struct fileinfo *file1));
+static int compare_version __P ((const struct fileinfo *file1,
+ const struct fileinfo *file2));
+static int rev_cmp_version __P ((const struct fileinfo *file2,
+ const struct fileinfo *file1));
static int decode_switches __P ((int argc, char **argv));
static int file_interesting __P ((const struct dirent *next));
static int gobble_file __P ((const char *name, int explicit_arg,
@@ -288,7 +293,7 @@ static enum time_type time_type;
int full_time;
-/* The file characteristic to sort by. Controlled by -t, -S, -U, -X. */
+/* The file characteristic to sort by. Controlled by -t, -S, -U, -X, -v. */
enum sort_type
{
@@ -296,7 +301,8 @@ enum sort_type
sort_name, /* default */
sort_extension, /* -X */
sort_time, /* -t */
- sort_size /* -S */
+ sort_size, /* -S */
+ sort_version /* -v */
};
static enum sort_type sort_type;
@@ -544,12 +550,12 @@ static enum format const formats[] =
static char const *const sort_args[] =
{
- "none", "time", "size", "extension", 0
+ "none", "time", "size", "extension", "version", 0
};
static enum sort_type const sort_types[] =
{
- sort_none, sort_time, sort_size, sort_extension
+ sort_none, sort_time, sort_size, sort_extension, sort_version
};
static char const *const time_args[] =
@@ -893,7 +899,7 @@ decode_switches (int argc, char **argv)
}
while ((c = getopt_long (argc, argv,
- "abcdfgiklmnopqrstuw:xABCDFGI:LNQRST:UX1",
+ "abcdfgiklmnopqrstuvw:xABCDFGI:LNQRST:UX1",
long_options, NULL)) != -1)
{
switch (c)
@@ -986,6 +992,10 @@ decode_switches (int argc, char **argv)
time_type = time_atime;
break;
+ case 'v':
+ sort_type = sort_version;
+ break;
+
case 'w':
if (xstrtol (optarg, NULL, 0, &tmp_long, NULL) != LONGINT_OK
|| tmp_long <= 0 || tmp_long > INT_MAX)
@@ -1908,6 +1918,9 @@ sort_files (void)
case sort_size:
func = sort_reverse ? rev_cmp_size : compare_size;
break;
+ case sort_version:
+ func = sort_reverse ? rev_cmp_version : compare_version;
+ break;
default:
abort ();
}
@@ -1966,6 +1979,18 @@ rev_cmp_size (const struct fileinfo *file2, const struct fileinfo *file1)
}
static int
+compare_version (const struct fileinfo *file1, const struct fileinfo *file2)
+{
+ return strverscmp (file1->name, file2->name);
+}
+
+static int
+rev_cmp_version (const struct fileinfo *file2, const struct fileinfo *file1)
+{
+ return strverscmp (file1->name, file2->name);
+}
+
+static int
compare_name (const struct fileinfo *file1, const struct fileinfo *file2)
{
return strcmp (file1->name, file2->name);
@@ -2897,6 +2922,7 @@ Sort entries alphabetically if none of -cftuSUX nor --sort.\n\
printf (_("\
-S sort by file size\n\
--sort=WORD ctime -c, extension -X, none -U, size -S,\n\
+ version -v\n\
status -c, time -t, atime -u, access -u, use -u\n\
--time=WORD show time as WORD instead of modification time:\n\
atime, access, use, ctime or status\n\
@@ -2904,6 +2930,7 @@ Sort entries alphabetically if none of -cftuSUX nor --sort.\n\
-T, --tabsize=COLS assume tab stops at each COLS instead of 8\n\
-u sort by last access time; with -l: show atime\n\
-U do not sort; list entries in directory order\n\
+ -v sort by version\n\
-w, --width=COLS assume screen width instead of current value\n\
-x list entries by lines instead of by columns\n\
-X sort alphabetically by entry extension\n\