blob: a5ecc987e1fcb47347bf8c47c82e51784ff1c3dd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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.
|