#! /bin/sh : # hce # # Author: Nikita Danilov # Keywords: H, C, E, Finnegans Wake, Joyce # # This file is (improper) part of hce. # # Hce is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # OPTVAL=`getopt -o s:vd: -n 'unhyphenize' -- "$@"` # Note the quotes around `$OPTVAL': they are essential! eval set -- "$OPTVAL" verbose=0 maxdist=0 sigla="h c e" while true ;do case "$1" in -v) verbose=$(($verbose + 1)) shift ;; -d) maxdist="$2" shift 2 ;; -s) sigla="$2" shift 2 ;; --) shift break ;; *) echo "Internal error!" exit 1 ;; esac done function reset() { local i num=1 patt="[" for s in $sigla ;do eval "${s}word=''" num=$(($num + 1)) patt=$patt$s done patt=$patt"]" pos=1 seq="" } function pushword() { local word local first local val word=$1 first=$(echo $word | cut -c1) varname="${first}word" eval "val=\$$varname" if [ x$val = x ] ;then eval "$varname='$word'" seq="$seq $word" pos=$(($pos + 1)) if [ $pos -eq $num ] ;then echo $seq reset fi else reset eval "$varname='$word'" seq=$word pos=2 fi } dist=0 reset while read do for word in `echo $REPLY | tr -c '[:alpha:]' '[ *]'` do echo $word done done | tr '[:upper:]' '[:lower:]' | \ while read ;do word=$REPLY case "$word" in $patt*) pushword $word dist=0 ;; *) dist=$(($dist + 1)) if [ $dist -gt $maxdist ] ;then reset fi ;; esac done