From 49997ac30b46c42a0366423cb2048f8257774805 Mon Sep 17 00:00:00 2001 From: Thorsten Töpper Date: Fri, 20 Jun 2025 01:45:13 +0200 Subject: Store everything from lstat() --- src/options.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/options.c') diff --git a/src/options.c b/src/options.c index 2136c83..e60d4a2 100644 --- a/src/options.c +++ b/src/options.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "output.h" #include "options.h" @@ -16,17 +17,26 @@ /* === GLOBAL VARIABLES === */ struct option long_options[] = { + { "long-timestamp", no_argument, 0, 0 }, { "reverse-sort", no_argument, 0, 0 }, { "show-hidden-entries", no_argument, 0, 0 }, { "sort-by", required_argument, 0, 0 }, - { "long-timestamp", no_argument, 0, 0 }, + { "time-field", required_argument, 0, 0 }, { 0, 0, 0, 0 } }; + bool option_sort_reverse_order = false; enum esort_type option_sort_type = SORT_BY_SIZE; bool option_show_hidden_entries = false; bool option_timestamp_long = false; +/* There are three fields regarding time, valid values 'a','c', 'm': + * st_atime / st_atim.tv_sec - time of the last access + * st_ctime / st_ctim.tv_sec - time of the last change to the inode + * st_mtime / st_mtim.tv_sec - time of last modification of the content + */ +char option_time_field = 'm'; + /* === IMPLEMENTATION === */ @@ -43,6 +53,8 @@ void usage(char *executable) { "Show hidden entries in the directory"); fprintf(stderr, " %-25s %2s %10s %s\n", "--sort-by", "", "size|time", "Sort either by time or size"); + fprintf(stderr, " %-25s %2s %10s %s\n", "--time-field", "", "a|c|m", + "Sort by (a)ccess, (c)hange or (m)odification time. Default: m"); } @@ -89,6 +101,27 @@ void set_option(const char *option_name, char *option_argument) { return; } + if (strcmp(option_name, "time-field") == 0) { + switch (option_argument[0]) { + case 'a': + option_time_field = 'a'; + break; + case 'c': + option_time_field = 'c'; + break; + case 'm': + option_time_field = 'm'; + break; + default: + /* Keep in mind: isgraph ignores space, but an explicit call --time-field ' ' is strange */ + LOGERR("WARNING: --time-field: invalid value %c 0x%02X - falling back to default m\n", + ((isgraph(option_argument[0])) ? option_argument[0] : ' '), option_argument[0]); + option_time_field = 'm'; + break; + }; + return; + } + LOGERR("ERROR: Option '%s' not recognized\n.", option_name); } -- cgit v1.2.3-70-g09d2