]> Lady’s Gitweb - HOMEDIR/blob - sed/czrj.sed
Add recordjar canonicalization script
[HOMEDIR] / sed / czrj.sed
1 #!/usr/bin/sed -f
2 # @(#)🏠📂 HOMEDIR sed/czrj.sed 2026-09-12T22:38:58Z
3 # SPDX-FileCopyrightText: 2026 Lady <https://www.ladys.computer/about/#lady>
4 # SPDX-License-Identifier: MPL-2.0
5
6 ## ⁌ Canonicalize recordjar
7 ##
8 ## ∎ Copyright © 2026 Lady [@ Ladys Computer].
9 ##
10 ## ⋮ This Source Code Form is subject to the terms of the Mozilla
11 ## Public License, version 2.0.
12 ## If a copy of the M·P·L was not distributed with this file, You can
13 ## obtain one at {🔗<https://mozilla.org/MPL/2.0/>}.
14
15 ## § Implementation
16
17 /^$/{
18 # Remove blank, nonfinal lines.
19 # If the final line is blank, skip to output (to ensure the
20 # hold space is handled before the program ends).
21 $b output
22 d
23 }
24
25 /^[ ]/{
26 # Add continuation lines to the hold space, then delete them
27 # if they are not final.
28 # If they are final, blank them out instead.
29 /^[ ]*$/!H
30 $!d
31 s/.*//
32 }
33
34 # At this point in the script, the current line is not a
35 # continuation line; that is, the previous field is done.
36 # If there is something in the hold space, it must be output
37 # and cleared.
38 # Then, the current line can be handled (added to the hold
39 # space if it introduces a new field).
40
41 :output
42 x;# switch to hold space
43 /^$/{
44 # If the hold space was empty, there is nothing to output.
45 x
46 b next
47 }
48 s/$/\n/;# add a final newline
49 s/[ ]\{1,\}/ /g;# collapse space on each line
50 s/^\\//;# drop leading backslash
51 s/ *\n */\n/g;# drop spaces around newlines
52 s/\n/ /1;# use tab to separate key and value
53 s/\\\{0,1\}\n//g;# drop all newlines (and preceding backslash)
54 s/ /\n /;# reinsert newline before tab
55 s/ \{1,\}/ /g;# collapse space on each line again
56 s/^ //;# drop leading key space
57 s/ :\n/:\n/;# drop trailing key space
58 s/ / /;# drop leading value space
59 s/ $//;# drop trailing value space
60 s/^%%/\\%%/;# add leading backslash if required
61 p;# print result
62 s/.*//;# clear pattern space
63 x;# switch back to current line
64 /^%%/{
65 # If the current line is a record separator, a separator can
66 # be output and no further processing is necessary.
67 a\
68 %%
69 d
70 }
71 /^$/{
72 # If the current line is empty and the final line, a final
73 # separator is output and the program ends.
74 # If it is empty but not final, no further processing is
75 # needed for this line.
76 # If it is final and not empty, see below.
77 $a\
78 %%
79 d
80 }
81
82 # At this point, the hold space is empty and the pattern space
83 # holds the current line (which is still not a continuation
84 # line).
85 # Empty lines and record separators can be discarded (they were
86 # handled above in the case where anything was output), and
87 # other lines initialize the next hold space.
88
89 :next
90 /^$/d
91 /^%%/d
92 s/:\([^:]*\)$/:\n\1/
93 x
94 ${
95 # If this is the last line, the hold space needs to be dealt
96 # with now.
97 b output
98 }
99 d
This page took 0.400165 seconds and 5 git commands to generate.