gensedfile 1022 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/bin/sh

if [ $# = 0 ]; then
    echo "Usage: $0 <keyword file> [<keyword substitution file>]"
    exit 1
fi

SOURCE=$1
if [ $# = 2 ]; then
   TARGET=$2
else
   TARGET=`basename ${SOURCE} .kw`.sed
fi

rm -f ${TARGET}; touch ${TARGET}

# THE ORDER OF THE SUBSTITUTIONS IS IMPORTANT !

echo "s/\([^@]\)@\([^@]\)/\1@@\2/g"                      >> ${TARGET}
echo "s/@@/@@@@/g"                                       >> ${TARGET}
echo "s/_@_/_@@_/g"                                      >> ${TARGET}
echo "s/{/\@{/g"                                         >> ${TARGET}
echo "s/}/\@}/g"                                         >> ${TARGET}
echo "s/-- \(.*\)$/-- @i{\1}/"                           >> ${TARGET}
echo "s/\([^-][^-][^\"]*\)\"\([^\"]*\)\"/\1\"@i{\2}\"/g" >> ${TARGET}

for kw in `cat ${SOURCE}`; do
    echo "s/^\([^-]* \)${kw}/\1@b{${kw}}/g"              >> ${TARGET}
    echo "s/^\( *\)${kw} /\1@b{${kw}} /g"                >> ${TARGET}
    echo "s/^${kw}$/@b{${kw}}/g"                         >> ${TARGET}
done