#!/usr/bin/sed -f # @(#)🏠📂 HOMEDIR sed/czrj.sed 2026-09-12T22:38:58Z # SPDX-FileCopyrightText: 2026 Lady # SPDX-License-Identifier: MPL-2.0 ## ⁌ Canonicalize recordjar ## ## ∎ Copyright © 2026 Lady [@ Ladys Computer]. ## ## ⋮ This Source Code Form is subject to the terms of the Mozilla ## Public License, version 2.0. ## If a copy of the M·P·L was not distributed with this file, You can ## obtain one at {🔗}. ## § Implementation /^$/{ # Remove blank, nonfinal lines. # If the final line is blank, skip to output (to ensure the # hold space is handled before the program ends). $b output d } /^[ ]/{ # Add continuation lines to the hold space, then delete them # if they are not final. # If they are final, blank them out instead. /^[ ]*$/!H $!d s/.*// } # At this point in the script, the current line is not a # continuation line; that is, the previous field is done. # If there is something in the hold space, it must be output # and cleared. # Then, the current line can be handled (added to the hold # space if it introduces a new field). :output x;# switch to hold space /^$/{ # If the hold space was empty, there is nothing to output. x b next } s/$/\n/;# add a final newline s/[ ]\{1,\}/ /g;# collapse space on each line s/^\\//;# drop leading backslash s/ *\n */\n/g;# drop spaces around newlines s/\n/ /1;# use tab to separate key and value s/\\\{0,1\}\n//g;# drop all newlines (and preceding backslash) s/ /\n /;# reinsert newline before tab s/ \{1,\}/ /g;# collapse space on each line again s/^ //;# drop leading key space s/ :\n/:\n/;# drop trailing key space s/ / /;# drop leading value space s/ $//;# drop trailing value space s/^%%/\\%%/;# add leading backslash if required p;# print result s/.*//;# clear pattern space x;# switch back to current line /^%%/{ # If the current line is a record separator, a separator can # be output and no further processing is necessary. a\ %% d } /^$/{ # If the current line is empty and the final line, a final # separator is output and the program ends. # If it is empty but not final, no further processing is # needed for this line. # If it is final and not empty, see below. $a\ %% d } # At this point, the hold space is empty and the pattern space # holds the current line (which is still not a continuation # line). # Empty lines and record separators can be discarded (they were # handled above in the case where anything was output), and # other lines initialize the next hold space. :next /^$/d /^%%/d s/:\([^:]*\)$/:\n\1/ x ${ # If this is the last line, the hold space needs to be dealt # with now. b output } d