mu/subx/apps/merge.subx

37 lines
645 B
Plaintext

# 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.