summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-08-08 15:33:20 -0400
committerJakob Kaivo <jkk@ung.org>2019-08-08 15:33:20 -0400
commitc8c21c5f650596454ec5619da8c911569baa6b42 (patch)
treec7fe2b945d1a193b2546e9d819cdbac5300f0e70
parent52b735b260281e9d907227a138d6aa57484018e0 (diff)
include sample program binhexbinary
-rw-r--r--.gitignore2
-rw-r--r--Makefile9
-rw-r--r--binhex.c21
3 files changed, 32 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..515eaf0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+binhex
+*.o
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..26a3cc0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+.POSIX:
+
+binhex: binhex.o binary.o
+
+binhex.o: binhex.c binary.h
+binary.o: binary.c binary.h
+
+clean:
+ rm -f binhex *.o
diff --git a/binhex.c b/binhex.c
new file mode 100644
index 0000000..1741573
--- /dev/null
+++ b/binhex.c
@@ -0,0 +1,21 @@
+#include <inttypes.h>
+#include <stdio.h>
+#include "binary.h"
+
+int main(int argc, char *argv[])
+{
+ for (int i = 1; i < argc; i++) {
+ int base = argv[i][0] == '0' && argv[i][1] == 'x' ? 16 : 2;
+ char s[BINSTRLEN];
+ uintmax_t n = strtoumax(argv[i], NULL, base);
+ if (argc > 2) {
+ printf("%s: ", argv[i]);
+ }
+ if (base == 2) {
+ printf("%jx\n", n);
+ } else {
+ printf("%s\n", binstr(sizeof(s), s, n));
+ }
+ }
+ return 0;
+}