aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@inria.fr>2026-01-03 22:44:07 +0100
committerTristan Riehs <tristan.riehs@inria.fr>2026-01-03 22:44:07 +0100
commitea09f1c40a7a3cd6186987e33e1c26cdef733b81 (patch)
tree45213fe09c79e1f5db1ef9baf6ad73f5337f9340
parentb27e9dd37d67d5a74ae307ae25a41361c1d22cfd (diff)
Add option parsing to "ftag export"
Also improve "ftad file add"'s.
-rw-r--r--src/main.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 10805f2..e896cb8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -336,9 +336,14 @@ static int table_next_id(sqlite3 *db, const char *table)
return last_id + 1;
}
-static void ftag_export_help(void)
+static void ftag_export_usage(void)
{
puts("Usage: ftag export [OPTION]... ARCHIVE");
+}
+
+static void ftag_export_help(void)
+{
+ ftag_export_usage();
puts("Export files from the database to an archive. Files are read from");
puts("standard input, one per line. Files have to be canonical names that");
puts("exist in the database.");
@@ -347,9 +352,9 @@ static void ftag_export_help(void)
A file name starting with a slash can be considered as a file to take
from the filesystem, not from the database. */
puts("Available options:");
+ puts(" -f TODO: use files' full names");
puts(" -h print this help");
puts(" -n TODO: add user name as a suffix");
- puts(" -f TODO: use files' full names");
}
/* Structure used to pass data from ftag_file_get_extension to its callback
@@ -425,6 +430,19 @@ static void ftag_file_get_path(char *out, int size, const char *file)
static void ftag_export(int argc, char **argv)
{
+ while ((argc > 0) && (argv[0][0] == '-')) {
+ switch (argv[0][1]) {
+ case 'h':
+ ftag_export_help();
+ exit(EXIT_SUCCESS);
+ default:
+ ftag_export_usage();
+ exit(EXIT_FAILURE);
+ }
+ argv++;
+ argc--;
+ }
+
if (argc != 1) {
ftag_export_help();
exit(EXIT_FAILURE);
@@ -727,10 +745,6 @@ static int get_sums_callback(void *_known_sums, int, char **cols, char **)
static void ftag_file_add(int argc, char **argv)
{
/* step 0: parse options */
- if (argc == 0) {
- ftag_file_add_usage();
- exit(EXIT_FAILURE);
- }
int interactive = 0;
int eliminate_duplicates = 1;
int encrypt = 1;
@@ -756,6 +770,11 @@ static void ftag_file_add(int argc, char **argv)
argc--;
}
+ if (argc == 0) {
+ ftag_file_add_usage();
+ exit(EXIT_FAILURE);
+ }
+
/* step 1: compute file sums */
uint32_t *sums = malloc(argc*sizeof(*sums));