-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcunfold2-2
executable file
·41 lines (38 loc) · 1.94 KB
/
lcunfold2-2
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
37
38
39
40
41
#! /bin/sed -Ef
# lcunfold2-2 - unfold lines using <backslash><newline><backslash>
# for line continuation
# Copyright (C) 2019,2022 Erik Auerswald <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Unfold (re-combine) lines folded as described in Internet Draft
# (I-D) draft-ietf-netmod-artwork-folding-04, now RFC 8792. In this
# script Strategy 2 ('\\') of line wrapping described in the I-D is
# supported. The I-D requires a header to signal beginning of text with
# folded (wrapped) lines, but no footer to signal the end of folded
# text. This script removes the header as intended.
# Note that this script does not check for valid input.
# Since this line folding technique does not use the concept of an escape
# character (although it might look this way) and is intended to be able
# to fold even content that already contains the folding sequence (without
# folding semantics), a recursive unfolding strategy cannot be used. Thus
# the whole file is read into the hold space and every folding sequence
# is removed once. If the data contains folding sequences after this step,
# they have been part of the unfolded input data and shall be kept. This
# is the basis of using "forced folding" to correctly work on input that
# already contains the folding sequence.
/NOTE: '\\\\' line wrapping per RFC 8792/{N;d}
{H;$!d}
x
s/^\n//
s/\\\n *\\//g