aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2022-08-24 14:37:00 +0300
committerJoursoir <chat@joursoir.net>2022-08-24 16:17:31 +0300
commit175b115e233c2181759c2f8a291a42724c0c549e (patch)
tree7c40b4b167c8cb1d4b8bfddf1d852c3113d2e753 /src
parent823aa07d5607ba165db3652541583f51e60c605d (diff)
downloadlock-password-175b115e233c2181759c2f8a291a42724c0c549e.tar.gz
lock-password-175b115e233c2181759c2f8a291a42724c0c549e.tar.bz2
lock-password-175b115e233c2181759c2f8a291a42724c0c549e.zip
cmd_showtree: replace errprint_*() with print_error()
Handle errors using goto instead of "do { ... } while(0)". This is one of the steps on the way to get rid of errprint_*() macros and handle errors by yourself. For more context see other patches under the same topic specified below. TOPIC=drop_errprint
Diffstat (limited to 'src')
-rw-r--r--src/exec-cmd.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/exec-cmd.c b/src/exec-cmd.c
index 19bacec..c574b7b 100644
--- a/src/exec-cmd.c
+++ b/src/exec-cmd.c
@@ -506,8 +506,10 @@ int cmd_showtree(int argc, char *argv[])
if(argv[optind]) {
result = check_sneaky_paths(argv[optind]);
- if(result)
- errprint_r(1, "You have used forbidden paths\n");
+ if(result) {
+ print_error("Error: You have used forbidden paths\n");
+ return 1;
+ }
path = malloc(sizeof(char) * (strlen(argv[optind]) + 1));
strcpy(path, argv[optind]);
}
@@ -516,44 +518,43 @@ int cmd_showtree(int argc, char *argv[])
strcpy(path, ".");
}
- do { // START_DO
-
- result = file_exist(path);
- if(result == F_ISDIR)
- {
- if(flag_copy) {
- errprint_ptr(&retval, 1,
- "You must type a passname, not a directory\n");
- break;
- }
-
- if(strcmp(path, ".") == 0)
- printf("Password Manager\n");
- else
- printf("Password Manager/%s\n", path);
- tree(path, "", flag_color);
+ result = file_exist(path);
+ if(result == F_ISDIR)
+ {
+ if(flag_copy) {
+ print_error("Error: You must type a passname, not a directory\n");
+ retval = 1;
+ goto out;
}
- else if(result == F_ISFILE)
- {
- char *pass = get_password(path);
- if(!pass) {
- errprint_ptr(&retval, 1, "Decrypt password failed\n");
- break;
- }
-
- if(flag_copy)
- copy_outside(pass);
- else
- printf("%s\n", pass);
-
- free(pass);
+
+ if(strcmp(path, ".") == 0)
+ printf("Password Manager\n");
+ else
+ printf("Password Manager/%s\n", path);
+ tree(path, "", flag_color);
+ }
+ else if(result == F_ISFILE)
+ {
+ char *pass = get_password(path);
+ if(!pass) {
+ print_error("Error: Decrypt password failed\n");
+ retval = 1;
+ goto out;
}
+
+ if(flag_copy)
+ copy_outside(pass);
else
- errprint_ptr(&retval, 1,
- "This path is not in the password storage\n");
+ printf("%s\n", pass);
- } while(0); // END_DO
+ free(pass);
+ }
+ else {
+ print_error("Error: This path is not in the password storage\n");
+ retval = 1;
+ }
+out:
free(path);
return retval;
}