summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorjwerle <joseph.werle@gmail.com>2024-12-31 13:48:07 -0500
committerjwerle <joseph.werle@gmail.com>2024-12-31 13:48:07 -0500
commit81a435207adabc6d8e4211728cdb55d17bd63a61 (patch)
treeb5af768ec7ade69abf31495688933b59e7212036 /main.c
parenta15164f747e51484360a01b404531fe51c2e5b7a (diff)
chore(): clean up
Diffstat (limited to 'main.c')
-rw-r--r--main.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/main.c b/main.c
index e3c680b..83ce046 100644
--- a/main.c
+++ b/main.c
@@ -1,31 +1,35 @@
-
/**
* `main.c' - murmurhash
*
- * copyright (c) 2014 joseph werle <joseph.werle@gmail.com>
+ * copyright (c) 2014-2025 joseph werle <joseph.werle@gmail.com>
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
+
#include "murmurhash.h"
-static void
-usage () {
+#define hash(key) murmurhash(key, (uint32_t) strlen(key), (uint32_t) atoi(seed));
+#define isopt(opt, str) (0 == strncmp(opt, str, strlen(str)))
+#define setopt(opt, key, var) { \
+ size_t len = strlen(key) + 1; \
+ for (int i = 0; i < len; ++i) { (*opt)++; } \
+ var = opt; \
+}
+
+static void usage () {
fprintf(stderr, "usage: murmur [-hV] [options]\n");
}
-static void
-help () {
+static void help () {
fprintf(stderr, "\noptions:\n");
fprintf(stderr, "\n --seed=[seed] hash seed (optional)");
fprintf(stderr, "\n");
}
-static char *
-read_stdin () {
+static char* read_stdin () {
size_t bsize = 1024;
size_t size = 1;
char buf[bsize];
@@ -64,24 +68,15 @@ read_stdin () {
return NULL;
}
-#define isopt(opt, str) (0 == strncmp(opt, str, strlen(str)))
-
-#define setopt(opt, key, var) { \
- size_t len = strlen(key) + 1; \
- for (int i = 0; i < len; ++i) { (*opt)++; } \
- var = opt; \
-}
-
-int
-main (int argc, char **argv) {
- char *buf = NULL;
- char *key = NULL;
- char *seed = NULL;
+int main (int argc, char** argv) {
+ char* buf = NULL;
+ char* key = NULL;
+ char* seed = NULL;
uint32_t h = 0;
// parse opts
- {
- char *opt = NULL;
+ do {
+ char* opt = NULL;
opt = *argv++; // unused
while ((opt = *argv++)) {
@@ -111,14 +106,12 @@ main (int argc, char **argv) {
}
}
}
- }
+ } while (0);
if (NULL == seed) {
seed = "0";
}
-#define hash(key) murmurhash(key, (uint32_t) strlen(key), (uint32_t) atoi(seed));
-
if (1 == isatty(0)) { return 1; }
else if (ferror(stdin)) { return 1; }
else {
@@ -136,7 +129,5 @@ main (int argc, char **argv) {
} while (NULL != key);
}
-#undef hash
-
return 0;
}