aboutsummaryrefslogtreecommitdiff
path: root/extract_src.py
diff options
context:
space:
mode:
authorJacob Janzen <jacob.a.s.janzen@gmail.com>2024-09-28 01:43:09 -0500
committerJacob Janzen <jacob.a.s.janzen@gmail.com>2024-09-28 01:43:09 -0500
commitd683509a0f412d080ffddde7e67bdf0ccd1f17f1 (patch)
treec97ffb024e5abdd1f57fac8b9acf27c7f1f0575f /extract_src.py
parentb7e84fa6048007cda7e6c8226e28bc2db90f792a (diff)
makefile works for nixos
Diffstat (limited to 'extract_src.py')
-rw-r--r--extract_src.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/extract_src.py b/extract_src.py
new file mode 100644
index 0000000..665c4c4
--- /dev/null
+++ b/extract_src.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys
+import re
+
+with open(sys.argv[1], "r") as inp:
+ with open(sys.argv[2], "w") as out:
+ in_src = False
+ startp = re.compile(r"^\s*#\+begin_src .* :tangle")
+ endp = re.compile(r"^\s*#\+end_src")
+ quoted = re.compile(r"^\s*,(\*|,\*|#\+)")
+
+ lines = inp.readlines()
+ curr = []
+ min_spaces = -1
+ for line in lines:
+ if startp.match(line):
+ in_src = True
+ elif endp.match(line):
+ in_src = False
+ for l in curr:
+ out.write(l[min_spaces:])
+ curr = []
+ min_spaces = -1
+ elif in_src:
+ spaces = len(line) - len(line.lstrip())
+ if min_spaces == -1 or min_spaces > spaces:
+ min_spaces = spaces
+ curr.append(re.sub(r"^(\s*),(\*|,\*|#\+|,#\+)", r"\1\2", line))