aboutsummaryrefslogtreecommitdiff
path: root/src/options.c
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2025-06-20 01:45:13 +0200
committerThorsten Töpper <atsutane@freethoughts.de>2025-06-20 01:45:13 +0200
commit49997ac30b46c42a0366423cb2048f8257774805 (patch)
tree6ff70c9eecf1276a64360840d697516400e3dcb1 /src/options.c
parent522ff099416b66868ef5782b6548d28917369b47 (diff)
downloaddir_monitor-49997ac30b46c42a0366423cb2048f8257774805.tar.gz
dir_monitor-49997ac30b46c42a0366423cb2048f8257774805.tar.bz2
Store everything from lstat()
Diffstat (limited to 'src/options.c')
-rw-r--r--src/options.c35
1 files changed, 34 insertions, 1 deletions
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 <string.h>
#include <getopt.h>
#include <stdbool.h>
+#include <ctype.h>
#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);
}