#!/bin/sh
#Prevziti vstupnich parametru
if [ "$1" = "-d" ]; then
if [ "$2" ]; then
dict=$2
else
exit -1
fi
if [ "$3" ]; then
file=$3
else
exit -1
fi
else
if [ "$1" ]; then
dict="dictionary.txt"
file=$1
else
exit -1
fi
fi
#Test existence souboru
if [ ! -r $dict ]; then
exit -1
fi
if [ ! -r $file ]; then
exit -1
fi
#Je potreba odstranit interpunkci a specialni znaky
#Soucasne se soubor nacita do pameti
tmp=`cat "$file" | sed "s/[*/|_\\().,!?+;:{}'\"-1234567890>-]/ /g"`
#konce radku se nahradi znakem !, aby se nemusely
#pouzit zanorene cykly
tmp=`echo "$tmp" | sed -r "s/(.+)$/\1 !/g"`
#Nacitani slovo po slovu a hledani ve slovniku.
#Pokud slovo nebylo nalezeno, ulozi se do seznamu
#nenalezenych slov, ktery bude na konci vytisknut.
#$line obsahuje cislo aktualniho radku
line=1
for (( i=1 ; ; i=$i+1 ))
do
wsearch=`echo $tmp | cut -d ' ' -f$i`
#Kdyz uz nic nenacte, je treba ukoncit smycku.
if ! [ "$wsearch" ]; then
break
fi
if [ "$wsearch" = "!" ]; then
line=$(( line+1 ))
continue
fi
dsearch=`cat $dict | grep -i -w $wsearch`
dcsearch=`cat $dict | grep -w $wsearch`
rword=`echo $dsearch | cut -d ':' -f1`
#Pokud nebylo slovo nalezeno ve slovniku, je to spatne.
if [ "$rword" ]; then
#Pokud bylo pismeno velky, musi se zvetsit i nahrazeny.
if ! [ "$dcsearch" ]; then
fl=`echo $rword | cut -c 1`
last=`echo $rword | cut -c 2-`
fl=`echo $fl | tr 'a-z' 'A-Z'`
rword=$fl$last
fi
sed -i 's/'$wsearch'/'$rword'/g' $file
else
echo "$line: $wsearch"
fi
done
exit 0
===== transform.sh =====
#!/bin/sh
# Parse parameters
INPUT=""
OUTPUT=""
STYLE=""
SPELL="0"
next_s="0"
for param in $@ ; do
if [ $next_s == "1" ] ; then
STYLE=$param
next_s="0"
continue
fi
if [ "$param" == "-s" ] ; then
next_s="1"
continue
fi
if [ "$param" == "-i" ] ; then
SPELL="1"
continue
fi
if [ "$INPUT" == "" ] ; then
INPUT=$param
else
OUTPUT=$param
fi
done
if [ -z "$INPUT" ] ; then
echo "Musite zadat vstupni soubor!"
exit 1
fi
if [ -z "$OUTPUT" ] ; then
echo "Musite zadat vystupni soubor!"
exit 2
fi
# Do spellchecking
if [ $SPELL = "1" ]; then
if [ -x spell.sh ] ; then
./spell.sh $INPUT > /dev/null
else
echo "xfilom00 nedodal spell.sh!"
exit 3
fi
fi
# Reset styles
styles_h1=""
styles_h2=""
styles_h3=""
styles_i=""
styles_u=""
styles_b=""
styles_a=""
styles_table=""
styles_tr=""
styles_td=""
styles_ul=""
styles_li=""
styles_br=""
styles_hr=""
# Load styles
if [ -n "$STYLE" ] ; then
eval `sed -r -e "s/\"/\\\\\\\\\"/g" \
-e "s/^([a-zA-Z0-9]+)\s*:\s*(.+)$/styles_\1=\" \2\"/g" $STYLE`
fi
# Find table's and list's begins and ends
egrep -n -B 1 "^\|" $INPUT | sed -r "s/^([0-9]+)-.*$/:\\1/g" | grep "^:" | sed -r "s/^:(.*)/\1a\/g" >tmp
egrep -n -A 1 "^\|" $INPUT | sed -r "s/^([0-9]+)-.*$/:\\1/g" | grep "^:" | sed -r "s/^:(.*)/\1i\<\/table\>/g" >>tmp
egrep -n -B 1 "^-" $INPUT | sed -r "s/^([0-9]+)-.*$/:\\1/g" | grep "^:" | sed -r "s/^:(.*)/\1a\/g" >>tmp
egrep -n -A 1 "^-" $INPUT | sed -r "s/^([0-9]+)-.*$/:\\1/g" | grep "^:" | sed -r "s/^:(.*)/\1i\<\/ul\>/g" >>tmp
# Body
echo "" > $OUTPUT
# Core
sed -f tmp $INPUT | sed -r \
-e "s/^! (.+)$/\\1\<\/h1\>/g" \
-e "s/^!! (.+)$/\\1\<\/h2\>/g" \
-e "s/^!!! (.+)$/\\1\<\/h3\>/g" \
-e "s/\/i\{([^\}]+)\}/\\1\<\/i\>/g" \
-e "s/\/u\{([^\}]+)\}/\\1\<\/u\>/g" \
-e "s/\/b\{([^\}]+)\}/\\1\<\/b\>/g" \
-e "s/[^\\]?\*([^\>]+)[\>]([^\*]+)\*/\\1\<\/a\>/g" \
-e "s/[^\\]?\*([^\*\>]+)\*/\\1\<\/a\>/g" \
-e "s/^\|(.+)\|$/\\\1\<\/td\>\<\/tr\>/g" \
-e "s/([^\\])\|/\1\<\/td\>\ /g" \
-e "s/^-(.+)/\- \1\<\/li\>/g" \
-e "s/^_$/\
/g" \
-e "s/^$/\
/g" \
-e "s/\\\([-\*!_\/\|\\\])/\1/g" \
>> $OUTPUT
# Body end
echo "" >> $OUTPUT
# Cleanup
rm tmp