aboutsummaryrefslogtreecommitdiff
path: root/src/options.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/options.c')
-rw-r--r--src/options.c76
1 files changed, 63 insertions, 13 deletions
diff --git a/src/options.c b/src/options.c
index 214a72c..749ee90 100644
--- a/src/options.c
+++ b/src/options.c
@@ -17,29 +17,42 @@
/* === GLOBAL VARIABLES === */
struct option long_options[] = {
+ { "all", no_argument, 0, 0 },
+ { "database", required_argument, 0 ,0 },
{ "help", no_argument, 0, 0 },
+ { "kv-storage", required_argument, 0, 0},
+ { "new-kv", no_argument, 0, 0 },
{ "quiet", no_argument, 0, 0 },
- { "show-hidden-entries", no_argument, 0, 0 },
{ 0, 0, 0, 0 }
};
+enum operation_modes option_mode = MODE_DEV_MESSED_UP;
+bool option_clean_kv = false;
bool option_quiet = false;
bool option_show_hidden_entries = false;
+char *option_gdbm_db_name = "/tmp/duplicate_finder.gdbm";
+char *option_sqlite_db_name = "duplicate_finder.sqlite";
char *exec_name;
/* === IMPLEMENTATION === */
void usage(char *executable) {
- fprintf(stderr, "Call: %s OPTIONS path_to_open\n", executable);
+ fprintf(stderr, "Call: %s OPTIONS scan|analyze [path]\n", executable);
fprintf(stderr, "\nOPTIONS are\n");
/* long name, short name, optional argument, explanation */
+ fprintf(stderr, " %-25s %2s %10s - %s\n", "--all", "-a", "",
+ "Also process and show files hidden on the filesystem");
+ fprintf(stderr, " %-25s %2s %10s - %s\n", "--database", "-d", "",
+ "fullname of the sqlite db to be used");
fprintf(stderr, " %-25s %2s %10s - %s\n", "--help", "-h", "",
"Show this message and exit");
+ fprintf(stderr, " %-25s %2s %10s - %s\n", "--kv-storage", "-k", "",
+ "fullname of the gdbm storage file used during filesystem scans");
+ fprintf(stderr, " %-25s %2s %10s - %s\n", "--new-kv", "", "",
+ "If the kv storage file already exists replace it with a new one");
fprintf(stderr, " %-25s %2s %10s - %s\n", "--quiet", "-q", "",
"Don't print error messages or warnings");
- fprintf(stderr, " %-25s %2s %10s - %s\n", "--show-hidden-entries", "-a", "",
- "Show hidden entries in the directory");
}
@@ -48,6 +61,10 @@ void set_option(const char *option_name, char *option_argument) {
DBGTRC("DEBUG: called with option_name '%s' and option_argument '%s'\n",
option_name, option_argument);
+ if (strcmp("all", option_name) == 0) {
+ option_show_hidden_entries = true;
+ return;
+ }
if (option_name == NULL)
return;
@@ -57,15 +74,15 @@ void set_option(const char *option_name, char *option_argument) {
exit(EXIT_SUCCESS);
}
+ if (strcmp("new-kv", option_name) == 0) {
+ option_clean_kv = true;
+ 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;
- }
/* options WITH arguments */
if (option_argument == NULL || option_argument[0] == '\0') {
@@ -74,6 +91,18 @@ void set_option(const char *option_name, char *option_argument) {
exit(EXIT_FAILURE);
}
+ /* No checks regarding validity of the paths here, if the lib can't
+ * work with it, it will react with a error which will be handled. */
+ if (strcmp("database", option_name) == 0) {
+ option_sqlite_db_name = option_argument;
+ return;
+ }
+
+ if (strcmp("kv-storage", option_name) == 0) {
+ option_gdbm_db_name = option_argument;
+ return;
+ }
+
LOGERR("ERROR: Option '%s' not recognized\n.", option_name);
}
@@ -85,7 +114,7 @@ int parse_arguments(int argc, char **argv) {
while(1) {
index = 0;
- c = getopt_long(argc, argv, "hqs", long_options, &index);
+ c = getopt_long(argc, argv, "ad:hk:q", long_options, &index);
if (c == -1) {
break;
@@ -95,15 +124,21 @@ int parse_arguments(int argc, char **argv) {
case 0:
set_option(long_options[index].name, optarg);
break;
+ case 'a':
+ option_show_hidden_entries = true;
+ break;
+ case 'd':
+ option_sqlite_db_name = optarg;
+ break;
case 'h':
usage(exec_name);
exit(EXIT_SUCCESS);
+ case 'k':
+ option_gdbm_db_name = optarg;
+ break;
case 'q':
option_quiet = true;
break;
- case 's':
- option_show_hidden_entries = true;
- break;
case '?':
break;
default:
@@ -113,6 +148,21 @@ int parse_arguments(int argc, char **argv) {
}
}
- return optind;
+ if (argc == optind) {
+ LOGERR("ERROR: Too few arguments, at least mode is required, see --help or man\n");
+ /* No external stuff touched so far, so just quit. */
+ exit(EXIT_FAILURE);
+ }
+
+ if (strcmp("scan", argv[optind]) == 0) {
+ option_mode = MODE_SCAN;
+ } else if (strcmp("analyze", argv[optind]) == 0) {
+ option_mode = MODE_ANALYZE_DB;
+ } else {
+ LOGERR("ERROR: No valid mode given see --help or man.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return optind++;
}