* Renamed to base4, to match this version's actual functionality. master
authorUrban Wallasch <urban.wallasch@freenet.de>
Sat, 21 Jul 2018 08:30:32 +0000 (10:30 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sat, 21 Jul 2018 08:30:32 +0000 (10:30 +0200)
.gitignore
base2.c [deleted file]
base4.c [new file with mode: 0644]
build.sh

index 162ad051b3f8aacfc1a5d1212697c09ddf43c4e8..550b72a71e1cf08a073e8de9b4f1b58f7564a561 100644 (file)
@@ -1,2 +1,2 @@
 *.o
-base2
+base4
diff --git a/base2.c b/base2.c
deleted file mode 100644 (file)
index b7db8a7..0000000
--- a/base2.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-static char *cd = "\t\n\r ";
-
-static int b2encode( FILE *inf, FILE *outf ) {
-    int c;
-    while ( EOF != ( c = fgetc( inf ) ) ) {
-        for ( int i = 6; i >= 0; i -= 2 )
-            fputc( cd[c >> i & 3], outf );
-    }
-    return ferror( inf );
-}
-
-static int b2decode( FILE *inf, FILE *outf ) {
-    char c;
-    unsigned d = 0;
-    int i = 0;
-    char *p;
-    while ( EOF != ( c = fgetc( inf ) ) ) {
-        if ( NULL == ( p = strchr( cd, c ) ) )
-            return EILSEQ;
-        d = d << 2 | ( p - cd );
-        if ( 4 == ++i ) {
-            fputc( d, outf );
-            i = d = 0;
-        }
-    }
-    return i ? -i : ferror( inf );
-}
-
-void usemsg( const char *n ) {
-    fprintf( stderr, "Usage:\n%s [-c] [-d] [-t ABCD]\n", n );
-    exit( EXIT_FAILURE );
-}
-
-int main( int argc, char *argv[] ) {
-    int res = 0, encode = 1;
-
-    for ( int oi = 1; oi < argc; ++oi ) {
-        if ( 0 == strcmp( argv[oi], "-c" ) )
-            encode = 1;
-        else if ( 0 == strcmp( argv[oi], "-d" ) )
-            encode = 0;
-        else if ( 0 == strcmp( argv[oi], "-t" ) ) {
-            ++oi;
-            if ( oi >= argc || strlen( argv[oi] ) < 4 )
-                usemsg( argv[0] );
-            cd = argv[oi];
-        }
-        else
-            usemsg( argv[0] );
-    }
-    res = encode ? b2encode( stdin, stdout ) : b2decode( stdin, stdout );
-    exit( res ? EXIT_FAILURE : EXIT_SUCCESS );
-}
diff --git a/base4.c b/base4.c
new file mode 100644 (file)
index 0000000..31c418d
--- /dev/null
+++ b/base4.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+static char *cd = "\t\n\r ";
+
+static int b4encode( FILE *inf, FILE *outf ) {
+    int c;
+    while ( EOF != ( c = fgetc( inf ) ) ) {
+        for ( int i = 6; i >= 0; i -= 2 )
+            fputc( cd[c >> i & 3], outf );
+    }
+    return ferror( inf );
+}
+
+static int b4decode( FILE *inf, FILE *outf ) {
+    char c;
+    unsigned d = 0;
+    int i = 0;
+    char *p;
+    while ( EOF != ( c = fgetc( inf ) ) ) {
+        if ( NULL == ( p = strchr( cd, c ) ) )
+            return EILSEQ;
+        d = d << 2 | ( p - cd );
+        if ( 4 == ++i ) {
+            fputc( d, outf );
+            i = d = 0;
+        }
+    }
+    return i ? -i : ferror( inf );
+}
+
+void usemsg( const char *n ) {
+    fprintf( stderr, "Usage:\n%s [-c] [-d] [-t ABCD]\n", n );
+    exit( EXIT_FAILURE );
+}
+
+int main( int argc, char *argv[] ) {
+    int res = 0, encode = 1;
+
+    for ( int oi = 1; oi < argc; ++oi ) {
+        if ( 0 == strcmp( argv[oi], "-c" ) )
+            encode = 1;
+        else if ( 0 == strcmp( argv[oi], "-d" ) )
+            encode = 0;
+        else if ( 0 == strcmp( argv[oi], "-t" ) ) {
+            ++oi;
+            if ( oi >= argc || strlen( argv[oi] ) < 4 )
+                usemsg( argv[0] );
+            cd = argv[oi];
+        }
+        else
+            usemsg( argv[0] );
+    }
+    res = encode ? b4encode( stdin, stdout ) : b4decode( stdin, stdout );
+    exit( res ? EXIT_FAILURE : EXIT_SUCCESS );
+}
index ca69251bd80bd00bc4dc81223deb86be9e26d3e6..a3fea445974e289793884a0637b3ffc82bca06d5 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1 +1 @@
-gcc -Wall -Wextra -std=c99 -pedantic -o base2 base2.c
+gcc -Wall -Wextra -std=c99 -pedantic -o base4 base4.c