about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorphoebos <ben@bvnf.space>2021-07-18 20:23:16 +0100
committerphoebos <ben@bvnf.space>2021-07-18 20:30:24 +0100
commitec67e00b392af1e1e5879be68eec92111d00b4ee (patch)
tree42f7f5f0e44ddb696c0897fcbf8325ec807cc2f5
parentd67dee2b26cca672fe32066e7aa511ee8bc0ccac (diff)
downloadkandr-base64.tar.gz
base64: add flag to change wrapped line length base64
-rw-r--r--base64.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/base64.c b/base64.c
index c41581d..e0c50cc 100644
--- 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");