aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-06-16 15:58:19 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-06-16 15:58:19 +0530
commit7d491fba56966311e09299a137dab90bb7ade124 (patch)
tree3f92d4682b8ace2ac625a880f33cf0e97ea117e6
parent840e0e406eea0b6397a33cdbd9a39474e5006a12 (diff)
(init): recursively search directory
-rw-r--r--.clang-format8
-rw-r--r--.envrc1
-rw-r--r--.gitignore3
-rw-r--r--Makefile15
-rw-r--r--config.h4
-rw-r--r--example/assets/.keep0
-rw-r--r--example/assets/abc0
-rw-r--r--example/index.html6
-rw-r--r--example/partials/hello.html2
-rw-r--r--example/partials/hi.html1
-rw-r--r--example/posts/a.html0
-rw-r--r--flake.lock27
-rw-r--r--flake.nix19
-rw-r--r--msg.c41
14 files changed, 127 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..65c9a5f
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,8 @@
+BasedOnStyle: GNU
+IndentWidth: 2
+TabWidth: 2
+BreakBeforeBraces: Linux
+SpaceBeforeParens: ControlStatements
+SpaceAfterCStyleCast: true
+BinPackArguments: false
+BinPackParameters: false
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..3550a30
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e283403
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.direnv/
+msg
+dist/ \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e11be89
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+CC := clang
+CFLAGS := -std=c99
+CFLAGS += -Wall -Wextra -Wpedantic
+
+all: CFLAGS += -O3
+all: clean msg
+
+debug: CFLAGS += -Og -g3 -glldb
+debug: clean msg
+
+msg: msg.c
+ $(CC) $(CFLAGS) $^ -o $@
+
+clean:
+ rm -f msg
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..f4bfa5a
--- /dev/null
+++ b/config.h
@@ -0,0 +1,4 @@
+static const char *directory = "example";
+static const char *partials_directory = "partials";
+static const char *assets_directory = "assets";
+static const char *output_directory = "dist";
diff --git a/example/assets/.keep b/example/assets/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/example/assets/.keep
diff --git a/example/assets/abc b/example/assets/abc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/example/assets/abc
diff --git a/example/index.html b/example/index.html
new file mode 100644
index 0000000..8760bcc
--- /dev/null
+++ b/example/index.html
@@ -0,0 +1,6 @@
+<html>
+ <head></head>
+ <body>
+ {{ include "hello.html" }}
+ </body>
+</html>
diff --git a/example/partials/hello.html b/example/partials/hello.html
new file mode 100644
index 0000000..169041a
--- /dev/null
+++ b/example/partials/hello.html
@@ -0,0 +1,2 @@
+<h1>Hello!</h1>
+{{ include "hi.html" }}
diff --git a/example/partials/hi.html b/example/partials/hi.html
new file mode 100644
index 0000000..32f7201
--- /dev/null
+++ b/example/partials/hi.html
@@ -0,0 +1 @@
+<h1>Hi!</h1>
diff --git a/example/posts/a.html b/example/posts/a.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/example/posts/a.html
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..1e5b514
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1749794982,
+ "narHash": "sha256-Kh9K4taXbVuaLC0IL+9HcfvxsSUx8dPB5s5weJcc9pc=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "ee930f9755f58096ac6e8ca94a1887e0534e2d81",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..09319dc
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,19 @@
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ };
+
+ outputs = { self, nixpkgs, ... }:
+ let
+ pkgs = import nixpkgs { system = "x86_64-linux"; config.allowUnfree = true; };
+ in {
+ devShells.x86_64-linux.default = pkgs.mkShell {
+ buildInputs = with pkgs; [
+ clang-tools
+ clang
+ lldb
+ gnumake
+ ];
+ };
+ };
+}
diff --git a/msg.c b/msg.c
new file mode 100644
index 0000000..0b5dc31
--- /dev/null
+++ b/msg.c
@@ -0,0 +1,41 @@
+#define _GNU_SOURCE
+
+#include <ftw.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+
+int
+fn(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
+{
+ (void) sb;
+
+ const char *basename = fpath + ftwbuf->base;
+
+ /* printf("%s\n", basename); */
+ if (typeflag == FTW_D) {
+ if (!strcmp(basename, partials_directory)
+ || !strcmp(basename, assets_directory))
+ return FTW_SKIP_SUBTREE;
+
+ return FTW_CONTINUE;
+ }
+
+ const char *path = fpath + strlen(directory) + 1;
+
+ printf("%s\n", fpath);
+ return FTW_CONTINUE;
+}
+
+int
+main(int argc, char **argv)
+{
+ (void) argc;
+ (void) argv;
+
+ nftw(directory, fn, 64, FTW_PHYS | FTW_ACTIONRETVAL);
+
+ return EXIT_SUCCESS;
+}