kandr

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit ec67e00b392af1e1e5879be68eec92111d00b4ee
parent d67dee2b26cca672fe32066e7aa511ee8bc0ccac
Author: phoebos <ben@bvnf.space>
Date:   Sun, 18 Jul 2021 20:23:16 +0100

base64: add flag to change wrapped line length

Diffstat:
Mbase64.c | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/base64.c b/base64.c @@ -51,7 +51,7 @@ const char tbl_base64[] = { }; static void usage(const char *name) { - fprintf(stderr, "usage: %s [-d] [FILE]\n", name); + fprintf(stderr, "usage: %s [-d] [-w COLS] [FILE]\n", name); } char *base64(unsigned char *i, ssize_t length, unsigned dflg){ @@ -102,13 +102,17 @@ void print_wrapped(char *s, int line_length){ int main(int argc, char **argv) { int c; + int wrap_cols = 76; unsigned dflg = 0; const char *name = argv[0]; - while ((c = getopt(argc, argv, "dh")) != -1) { + while ((c = getopt(argc, argv, "dhw:")) != -1) { switch(c) { case 'd': dflg++; break; + case 'w': + wrap_cols = atoi(optarg); + break; case 'h': usage(name); return 0; @@ -161,7 +165,7 @@ int main(int argc, char **argv) { } char *output = base64(buf, used, dflg); - print_wrapped(output, 76); + print_wrapped(output, wrap_cols); if (close(fd) != 0) { perror("close");