aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/options.h1
-rw-r--r--include/output.h3
-rw-r--r--man/dir_monitor.1.adoc3
-rw-r--r--src/options.c14
4 files changed, 19 insertions, 2 deletions
diff --git a/include/options.h b/include/options.h
index cae9aa0..c92dbdf 100644
--- a/include/options.h
+++ b/include/options.h
@@ -30,6 +30,7 @@ extern bool option_sort_reverse_order;
extern enum esort_type option_sort_type;
extern bool option_print_boxed_table;
extern bool option_print_header;
+extern bool option_quiet;
extern bool option_resolve_symlinks;
extern bool option_show_hidden_entries;
extern bool option_timestamp_long;
diff --git a/include/output.h b/include/output.h
index 53f0869..38546aa 100644
--- a/include/output.h
+++ b/include/output.h
@@ -8,10 +8,11 @@
#define OUTPUT_H
#include <stdio.h>
+#include "options.h"
#include "data_management.h"
-#define LOGERR(...) {fprintf(stderr, "[%s:%d] %s: ", __FILE__, __LINE__, __func__); fprintf(stderr, __VA_ARGS__);}
+#define LOGERR(...) {if (!option_quiet){ fprintf(stderr, "[%s:%d] %s: ", __FILE__, __LINE__, __func__); fprintf(stderr, __VA_ARGS__); }}
#ifdef DEBUGBUILD
#define DBGTRC(...) LOGERR(__VA_ARGS__)
diff --git a/man/dir_monitor.1.adoc b/man/dir_monitor.1.adoc
index f890fb6..6aa15fc 100644
--- a/man/dir_monitor.1.adoc
+++ b/man/dir_monitor.1.adoc
@@ -34,6 +34,9 @@ Print output in form of a boxed table
**--print-header**, **-H**::
Print a header above the columns
+**--quiet**, **-q**::
+Suppress error and warning messages.
+
**--resolve-symlinks**::
The destination (name) of a symlink is resolved
diff --git a/src/options.c b/src/options.c
index 235792d..6aa913b 100644
--- a/src/options.c
+++ b/src/options.c
@@ -23,6 +23,7 @@ struct option long_options[] = {
{ "long-timestamp", no_argument, 0, 0 },
{ "print-boxed", no_argument, 0, 0 },
{ "print-header", no_argument, 0, 0 },
+ { "quiet", no_argument, 0, 0 },
{ "resolve-symlinks", no_argument, 0, 0 },
{ "reverse-sort", no_argument, 0, 0 },
{ "show-hidden-entries", no_argument, 0, 0 },
@@ -35,6 +36,7 @@ bool option_sort_reverse_order = false;
enum esort_type option_sort_type = SORT_BY_SIZE;
bool option_print_boxed_table = false;
bool option_print_header = false;
+bool option_quiet = false;
bool option_resolve_symlinks = false;
bool option_show_hidden_entries = false;
bool option_timestamp_long = false;
@@ -65,6 +67,8 @@ void usage(char *executable) {
"Print a boxed table");
fprintf(stderr, " %-25s %2s %10s - %s\n", "--print-header", "-H", "",
"Print a header above the columns");
+ fprintf(stderr, " %-25s %2s %10s - %s\n", "--quiet", "-q", "",
+ "Don't print error messages or warnings");
fprintf(stderr, " %-25s %2s %10s - %s\n", "--resolve-symlinks", "", "",
"the destination (name) of a symlink is resolved");
fprintf(stderr, " %-25s %2s %10s - %s\n", "--reverse-sort", "", "",
@@ -136,6 +140,11 @@ void set_option(const char *option_name, char *option_argument) {
return;
}
+ if (strcmp("quiet", option_name) == 0) {
+ option_quiet = true;
+ return;
+ }
+
if (strcmp("show-hidden-entries", option_name) == 0) {
option_show_hidden_entries = true;
return;
@@ -199,7 +208,7 @@ int parse_arguments(int argc, char **argv) {
while(1) {
index = 0;
- c = getopt_long(argc, argv, "abHhtf:", long_options, &index);
+ c = getopt_long(argc, argv, "abf:Hhqt", long_options, &index);
if (c == -1) {
break;
@@ -224,6 +233,9 @@ int parse_arguments(int argc, char **argv) {
case 'H':
option_print_header = true;
break;
+ case 'q':
+ option_quiet = true;
+ break;
case 't':
option_timestamp_long = true;
break;