#! /usr/bin/gawk -f # Last edited on 2003-07-21 18:31:42 by stolfi BEGIN { prevkey = ""; prevval = ""; prevsticy = 0; } ($2 == "=") { key = $1; val = $0; gsub(/^[^=]*[=] */, "", val); # Discard empty bits of entry: if (match(val, /^ *[\{][@][\}] *$/)) { next; } # Does this line want to be joined with the previous one? sticky = match(val, /^ *[\{][+][@]/); # Should we join with previous entry? if ((prevkey == key) && (sticky || prevsticky)) { # Splice entries: gsub(/^ *[\{][+]*[@]*/, "", val); gsub(/[@]*[+]*[\}] *$/, "", prevval); prevval = (prevval val); # printf "[SPLICE %s]", key > "/dev/stderr"; } else { if (sticky || prevsticky) { printf "** frustrated splice\n «%s»\n «%s»\n", \ prevval, val > "/dev/stderr"; } flush_prev(); prevkey = key; prevval = val; } # Does this line wants to be spliced with the following one? prevsticky = match(prevval, /[@][+][\}] *$/); next; } // { if (prevkey != "") { flush_prev(); } print; next; } END { if (prevkey != "") { flush_prev(); } } function flush_prev( ) { if ((prevkey != "") || (prevval != "")) { printf " %s = %s\n", prevkey, prevval; # printf "[FLUSH %s]", prevkey > "/dev/stderr"; } prevkey = ""; prevval = ""; }