#!/bin/sh
DICTIONARY=/usr/local/muller/dict/sort/muller.koi
h0="ver.2.0 E.S.Cymbalyuk 1999. 
\"mova\" is a \"bash\" script for search in dictionary a word or a string. Use for help: mova -h"
h1="mova OPTION word1 (word2) (word3) ..."
h2="Possible OPTION is -wo or -wop or -st or -stp"
h3="-wo     search one word \"word1\" in dictionary only
 from beginning of each article" 
h4="-wop    search string of simbols \"word1\" from beginning of each article 
as first part of first word in article"
h5="-st     search string of words \"word1+word2+word3+...\" in body
of dictionary article"
h6="-stp    search string of simbols as \"word1+word2+word3...\" 
in body of dictionary"

case $# in
0) echo $h0; exit;;
1) echo $h0; echo $h1; echo $h2; echo $h3; echo $h4; echo $h5; echo $h6; exit;;
esac

SearchBody () {
    grep $1 "^$STRING" "$DICTIONARY".`echo $SearchSTRING|sed 's/\(^.\)\(.*\)/\1/'` | sed 's/$/\
    /g; s/ _[IVX]/\
      &/g; s/ [1-9]\. /\
        &/g; s/ [1-9][0-9]*) /\
          &/g; s/ []) /\
            &/g'|fmt -s -w 45 | tee -a /tmp/muller.log
}



case $1 in

-wo) 
    STRING=`echo $2|sed 's/^[ ]*//g'`
    SearchSTRING=$STRING
    SearchBody '-E -h -i -w'
    ;;

-wop)
    STRING=`echo $2|sed 's/^[ ]*//g'`
    SearchSTRING=$STRING
    SearchBody '-E -h -i'
    ;;

-st) 
    for i in $*
    do
	STRING=$STRING\ $i
    done
    STRING=`echo $STRING|sed 's/^[ ]*-st //g'`
    for i in , "(" - 2 3 _ a b c d e f g h i j k l m n o p q r s t u v w x y z
    do 
	SearchSTRING=$i"as"
	SearchBody '-h -i -w'
    done
    ;;
    
-stp) 
    for i in $*
    do
	STRING=$STRING\ $i
    done
    STRING=`echo $STRING|sed 's/^[ ]*-stp //g'`
    for i in , "(" - 2 3 _ a b c d e f g h i j k l m n o p q r s t u v w x y z
    do 
	SearchSTRING=$i"as"
	SearchBody '-h -i'
    done
    ;;
*) 
    echo $h0; 
esac
