aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2022-08-21 15:46:12 +0300
committerJoursoir <chat@joursoir.net>2022-08-22 00:40:17 +0300
commit3f22a4390ef116593158b4c9b36e923f6d853aee (patch)
tree30d9859d31423779274124969e1c52958be1f357
parentb018da7fb3d400036c38a3af6554ab25e408b9c8 (diff)
downloadlock-password-3f22a4390ef116593158b4c9b36e923f6d853aee.tar.gz
lock-password-3f22a4390ef116593158b4c9b36e923f6d853aee.tar.bz2
lock-password-3f22a4390ef116593158b4c9b36e923f6d853aee.zip
tree: usageprint() macro no longer returns an error by itself
This patch also does: - Moves usageprint() from constants.h to output.h - Returns an error after using useprint() clearly.
-rw-r--r--src/constants.h6
-rw-r--r--src/exec-cmd.c41
-rw-r--r--src/output.h1
3 files changed, 32 insertions, 16 deletions
diff --git a/src/constants.h b/src/constants.h
index 85772c7..6501f3c 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -38,12 +38,6 @@
*PTR = RETVAL; \
} while(0)
-#define usageprint(...) \
- do { \
- fprintf(stdout, "Usage: lpass " __VA_ARGS__); \
- return 1; \
- } while(0)
-
#ifdef DEBUG
#define dbgprint(...) fprintf(stderr, "Debug: " __VA_ARGS__)
#else
diff --git a/src/exec-cmd.c b/src/exec-cmd.c
index 7724023..686ada7 100644
--- a/src/exec-cmd.c
+++ b/src/exec-cmd.c
@@ -32,14 +32,17 @@
#include "routines.h"
#include "exec-cmd.h"
#include "tree.h"
+#include "output.h"
int cmd_init(int argc, char *argv[])
{
const char description[] = "init gpg-key\n";
int retval = 0, result;
char *gpg_key = argv[2];
- if(gpg_key == NULL)
+ if(gpg_key == NULL) {
usageprint("%s", description);
+ return 1;
+ }
// create .gpg-key in storage
FILE *filekey = fopen(GPGKEY_FILE, "w");
@@ -73,13 +76,17 @@ int cmd_insert(int argc, char *argv[])
case 'e': { flag_echo = 1; break; }
case 'f': { flag_force = 1; break; }
case 'c': { flag_copy = 1; break; }
- default: usageprint("%s", description);
+ default:
+ usageprint("%s", description);
+ return 1;
}
}
char *path = argv[optind];
- if(path == NULL)
+ if(path == NULL) {
usageprint("%s", description);
+ return 1;
+ }
result = check_sneaky_paths(path);
if(result)
@@ -156,8 +163,10 @@ int cmd_edit(int argc, char *argv[])
char path_tmpfile[] = "/dev/shm/lpass.XXXXXX";
char *editor, *password;
char *path = argv[1];
- if(!path)
+ if(!path) {
usageprint("%s", description);
+ return 1;
+ }
result = check_sneaky_paths(path);
if(result)
@@ -255,13 +264,17 @@ int cmd_generate(int argc, char *argv[])
case 'l': { pass_length = atoi(optarg); break; }
case 'f': { flag_force = 1; break; }
case 'c': { flag_copy = 1; break; }
- default: usageprint("%s", description);
+ default:
+ usageprint("%s", description);
+ return 1;
}
}
char *path = argv[optind];
- if(path == NULL)
+ if(path == NULL) {
usageprint("%s", description);
+ return 1;
+ }
if(pass_length < minlen_pass || pass_length > maxlen_pass)
errprint_r(1, "You typed an incorrect length\n");
@@ -303,8 +316,10 @@ int cmd_remove(int argc, char *argv[])
const char description[] = "rm passname\n";
int result;
char *path = argv[1];
- if(!path)
+ if(!path) {
usageprint("%s", description);
+ return 1;
+ }
result = check_sneaky_paths(path);
if(result)
@@ -340,12 +355,16 @@ int cmd_move(int argc, char *argv[])
while((result = getopt_long(argc, argv, "f", long_options, NULL)) != -1) {
switch(result) {
case 'f': { flag_force = 1; break; }
- default: usageprint("%s", description);
+ default:
+ usageprint("%s", description);
+ return 1;
}
}
- if(!argv[optind] || !argv[optind+1])
+ if(!argv[optind] || !argv[optind+1]) {
usageprint("%s", description);
+ return 1;
+ }
char *old_path = argv[optind];
char *new_path = argv[optind+1];
@@ -434,7 +453,9 @@ int cmd_showtree(int argc, char *argv[])
switch(result) {
case 'c': { flag_copy = 1; break; }
case 'C': { flag_color = 0; break; }
- default: usageprint("%s", description);
+ default:
+ usageprint("%s", description);
+ return 1;
}
}
diff --git a/src/output.h b/src/output.h
index 3be5f59..7925e28 100644
--- a/src/output.h
+++ b/src/output.h
@@ -22,5 +22,6 @@
#include <stdio.h>
#define print_error(...) fprintf(stderr, __VA_ARGS__)
+#define usageprint(...) fprintf(stderr, "Usage: lpass " __VA_ARGS__)
#endif /* LPASS_OUTPUT_H */