From: Lady Date: Sat, 12 Sep 2026 22:38:58 +0000 (-0400) Subject: Add recordjar canonicalization script X-Git-Url: https://git.ladys.computer/HOMEDIR/commitdiff_plain?ds=sidebyside Add recordjar canonicalization script Message-type: text/lesml --- diff --git a/bin/czrj b/bin/czrj new file mode 120000 index 0000000..da42092 --- /dev/null +++ b/bin/czrj @@ -0,0 +1 @@ +../sed/czrj.sed \ No newline at end of file diff --git a/sed/czrj.sed b/sed/czrj.sed new file mode 100755 index 0000000..3c58ab1 --- /dev/null +++ b/sed/czrj.sed @@ -0,0 +1,99 @@ +#!/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