Add new ls option -d.
authorAndre Noll <maan@systemlinux.org>
Sat, 13 Jun 2009 11:53:42 +0000 (13:53 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 13 Jun 2009 11:53:42 +0000 (13:53 +0200)
This is useful for the conversion script that transforms the afs
database to the 0.4 format.

NEWS
afs.cmd
aft.c

diff --git a/NEWS b/NEWS
index 20e5105..4d775ec 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ NEWS
        - improved signal handling
        - variable fec output buffer size
        - --log_color actually works
+       - new ls option: -d (print dates as seconds after the epoch)
 
 -----------------------------------------
 0.3.4 (2009-05-07) "elliptic inheritance"
diff --git a/afs.cmd b/afs.cmd
index da4b3f8..0af4511 100644 (file)
--- a/afs.cmd
+++ b/afs.cmd
@@ -41,7 +41,7 @@ H: only the tables given by table_name... are created.
 N: ls
 P: AFS_READ
 D: List audio files.
-U: ls [-l[s|l|v|m]] -p -a -r -s{p|s|l|n|f|c|i|y|b|d|a} [pattern...]
+U: ls [-l[s|l|v|m]] [-p] [-a] [-r] [-d] [-s{p|s|l|n|f|c|i|y|b|d|a}] [pattern...]
 H: Print a list of all audio files matching pattern.
 H:
 H: Options:
@@ -66,6 +66,8 @@ H:    playlist.
 H:
 H: -r  Reverse sort order.
 H:
+H: -d  Print dates as seconds after the epoch.
+H:
 H: -s  Change sort order. Defaults to alphabetical path sort if not given.
 H:
 H:             -sp:  sort by path.
diff --git a/aft.c b/aft.c
index 995c755..20fa3a9 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -74,6 +74,8 @@ enum ls_flags {
        LS_FLAG_ADMISSIBLE_ONLY = 2,
        /** -r */
        LS_FLAG_REVERSE = 4,
+       /** -d */
+       LS_FLAG_UNIXDATE = 8,
 };
 
 /**
@@ -800,10 +802,15 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts,
                goto out;
        }
        get_attribute_bitmap(&afsi->attributes, att_buf);
-       ret = get_local_time(&afsi->last_played, last_played_time,
-               sizeof(last_played_time), current_time, opts->mode);
-       if (ret < 0)
-               goto out;
+       if (opts->flags & LS_FLAG_UNIXDATE)
+               sprintf(last_played_time, "%llu",
+                       (long long unsigned)afsi->last_played);
+       else {
+               ret = get_local_time(&afsi->last_played, last_played_time,
+                       sizeof(last_played_time), current_time, opts->mode);
+               if (ret < 0)
+                       goto out;
+       }
        get_duration_buf(afhi->seconds_total, duration_buf, opts);
        if (have_score) {
                if (opts->mode == LS_MODE_LONG)
@@ -1458,6 +1465,10 @@ int com_ls(int fd, int argc, char * const * const argv)
                        flags |= LS_FLAG_REVERSE;
                        continue;
                }
+               if (!strcmp(arg, "-d")) {
+                       flags |= LS_FLAG_UNIXDATE;
+                       continue;
+               }
                if (!strncmp(arg, "-s", 2)) {
                        if (!*(arg + 2) || *(arg + 3))
                                return -E_AFT_SYNTAX;