#! /bin/sh
# This script takes as input a list of words (one per line), and creates a sed
# script that "glues together" each occurrence of any of these words on the sed
# script's input; where "glues together" means inserting a u+feff (zero-width
# non-breaking space) character between each pair of characters, so that that
# word doesn't get split over two lines.

cat <<EOF
#! /bin/sed -f
# This sed script insert a u+feff (zero-width non-breaking space) character
# between each pair of characters of each of a certain set of words, thus
# ensuring that that word doesn't get split over more than one line.
#
# If the input document contains what looks like words that overlap each other,
# then u+feff is inserted throughout the sequence: i.e. if the input document
# contains ABC, where both AB and BC are words in our list, then the whole
# string ABC is kept on a single line.

EOF

sed 's/^  *//; s/  *$//; h; s/\(.\)/\1﻿/g; s,﻿$,/g;,; x; s/\(.\)/\1﻿*/g; s,^,s/,; s,﻿\*$,/,; G;' "$@" | tr -d \\n | tr \; \\n
# (Note that the above contains embedded zero-width non-breaking space
# characters, which might or might not be visible.)
