about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--subx/apps/merge.subx36
1 files changed, 36 insertions, 0 deletions
diff --git a/subx/apps/merge.subx b/subx/apps/merge.subx
new file mode 100644
index 00000000..a5ecc987
--- /dev/null
+++ b/subx/apps/merge.subx
@@ -0,0 +1,36 @@
+# Read a text file of SubX segment 'fragments' with duplicate names, and emit
+# a list of 'merged' segments.
+#
+# Example input:
+#   == A
+#   a
+#   b
+#   c
+#   == B
+#   d
+#   e
+#   == A
+#   f
+#   g
+#   == A
+#   h
+#
+# Output:
+#   == A
+#   h
+#   f
+#   g
+#   a
+#   b
+#   c
+#   == B
+#   d
+#   e
+#
+# The output gives each segment the contents of all its fragments, with later
+# fragments *prepended* to earlier ones.
+#
+# Prepending necessitates buffering output until the end. We'll convert
+# fragments to distinct streams, maintain each segment as a linked list of
+# fragments that's easy to prepend to, and finally emit the linked lists in
+# order.