From 3f22a4390ef116593158b4c9b36e923f6d853aee Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sun, 21 Aug 2022 15:46:12 +0300 Subject: 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. --- src/constants.h | 6 ------ src/exec-cmd.c | 41 +++++++++++++++++++++++++++++++---------- src/output.h | 1 + 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 #define print_error(...) fprintf(stderr, __VA_ARGS__) +#define usageprint(...) fprintf(stderr, "Usage: lpass " __VA_ARGS__) #endif /* LPASS_OUTPUT_H */ -- cgit v1.2.3-18-g5258