From 534db3ad6e744e55c0ae7112b53722d008369394 Mon Sep 17 00:00:00 2001 From: Heiko Reese Date: Sat, 11 Sep 2021 02:13:22 +0200 Subject: [PATCH] Add option to suppress a newline at the end of the output. --- ...libexim-encrypt-dlfunc-decrypt-secretbox.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libexim-encrypt-dlfunc-decrypt-secretbox.c b/src/libexim-encrypt-dlfunc-decrypt-secretbox.c index feeb95b..5a0dcfd 100644 --- a/src/libexim-encrypt-dlfunc-decrypt-secretbox.c +++ b/src/libexim-encrypt-dlfunc-decrypt-secretbox.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "common.c" #define ENVVAR_PASSWORD_NAME "LIBEXIM_PASSWORD" @@ -13,12 +14,16 @@ void print_usage(char * progname) { printf("Password:\n"); printf(" -p, --password PASSWORD decrypt using PASSWORD\n"); printf("\n"); - printf(" If the environment variable LIBEXIM_PASSWORD is set the password is read from it.\n"); + printf(" If the environment variable LIBEXIM_PASSWORD is set the password is read from there.\n"); + printf(" Setting a password with -p/--password overwrites this mechanism.\n"); printf("\n"); printf("Select input:\n"); printf(" -c, --input STRING decrypt contents of STRING\n"); printf(" -f, --infile FILE decrypt contents of the first line of file FILE\n"); printf("\n"); + printf("Output:\n"); + printf(" -n, --no-newline Do not add a newline to the output\n"); + printf("\n"); } typedef enum { @@ -36,6 +41,7 @@ int main(int argc, char *argv[]) { size_t password_len; char *password; char *password_env; + bool add_newline = true; seen_args mode = NONE; seen_args input = NONE; @@ -46,11 +52,12 @@ int main(int argc, char *argv[]) { } // define arguments - const char *shortargs = "p:ef:"; + const char *shortargs = "p:ef:n"; static struct option long_options[] = { {"password", required_argument, NULL, 'p'}, {"pass-from-env", no_argument, NULL, 'e'}, {"infile", required_argument, NULL, 'f'}, + {"no-newline", no_argument, NULL, 'n'}, {0, 0, 0, 0} }; @@ -78,6 +85,9 @@ int main(int argc, char *argv[]) { cipherstring = read_first_line(optarg); input |= INFILE; break; + case 'n': + add_newline = false; + break; } } @@ -136,5 +146,9 @@ int main(int argc, char *argv[]) { } // print cleartext to stdout - fprintf(stdout, "%s", (const char *) cleartext); + if (add_newline == true) { + fprintf(stdout, "%s\n", (const char *) cleartext); + } else { + fprintf(stdout, "%s", (const char *) cleartext); + } } \ No newline at end of file