summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile28
-rw-r--r--core/rdar.c66
3 files changed, 97 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d69e188
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.o
+*.d
+/rdar
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4d83e8c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+#
+# Copyright (c) 2026, Chloe M.
+# Provided under the BSD-3 clause.``
+#
+
+CFILES = $(shell find . -name "*.c")
+OFILES = $(CFILES:.c=.o)
+DFILES = $(CFILES:.c=.d)
+
+CC = \
+ gcc
+
+CFLAGS = \
+ -Wall \
+ -pedantic \
+ -MMD
+
+.PHONY: all
+all: rdar
+
+.PHONY: rdar
+rdar: $(OFILES)
+ $(CC) $^ -o $@
+
+-include $(DFILES)
+%.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
diff --git a/core/rdar.c b/core/rdar.c
new file mode 100644
index 0000000..ff5022f
--- /dev/null
+++ b/core/rdar.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2026, Chloe M.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stddef.h>
+
+/* Version conversion macros */
+#define VERSION_U16(MAJOR, MINOR) \
+ (((MINOR) << 8) | (MAJOR))
+#define VERSION_MAJOR(VERSION) \
+ ((VERSION) & 0xFF)
+#define VERSION_MINOR(VERSION) \
+ (((VERSION) >> 8) & 0xFF)
+
+/*
+ * Software version
+ *
+ * XXX: We encode it as a U16 so that we may bundle it
+ * with the file data as binary.
+ */
+#define RDAR_VERSION VERSION_U16(1, 0) /* v1.0 */
+
+static void
+help(void)
+{
+ printf("usage: ./rdar <... flags>\n");
+ printf("[-h] Display this help menu\n");
+ printf("[-v] Display the program version\n");
+}
+
+static void
+version(void)
+{
+ uint16_t Major, Minor;
+
+ Major = VERSION_MAJOR(RDAR_VERSION);
+ Minor = VERSION_MINOR(RDAR_VERSION);
+ printf("Version v%d.%d\n", Major, Minor);
+}
+
+int
+main(int argc, char **argv)
+{
+ int opt;
+
+ if (argc < 2) {
+ printf("fatal: too few arguments\n");
+ help();
+ return -1;
+ }
+
+ while ((opt = getopt(argc, argv, "hv")) != -1) {
+ switch (opt) {
+ case 'h':
+ help();
+ return -1;
+ case 'v':
+ version();
+ return -1;
+ }
+ }
+}