: ########################################################################## # Title : translate - translate words between German and English # Author : Heiner Steven # Date : 1999-04-27 # Requires : dumphtmltbl, [nicecol], urlencode, wget # Category : WWW # SCCS-Id. : @(#) translate 1.15 05/04/18 ########################################################################## # Description # Uses the LEO online dictionary (http://www.leo.org) to translate # words between German and english ########################################################################## PN=`basename "$0"` # Program name VER='1.15' # Set this variable to prevent auto-detection of the fastest AWK: #: ${AWK:=gawk} # Program to get an URL specified on the command line, and write the # data to standard output : ${GETURL:=wget} : ${GETURLFLAGS="-q -O -"} CGIURL='http://dict.leo.org/ende?search=' usage () { echo >&2 "$PN - translate words between German and English, $VER usage: $PN word [word ...] This script accesses the LEO translation service http://dict.leo.org/ ." exit 1 } msg () { for msgLine do echo "$PN: $msgLine" >&2 done } fatal () { msg "$@"; exit 1; } ############################################################################### # searchprog - search program using search PATH # usage: searchprog program ############################################################################### searchprog () { _search=$1; shift for _dir in `echo "$PATH" | sed "s/^:/.:/;s/:\$/:./;s/:/ /g"` do [ -x "$_dir/$_search" ] || continue echo "$_dir/$_search" return 0 done return 1 } ############################################################################### while getopts :h opt do case "$opt" in # your flags here h) usage;; \?) usage;; esac done shift `expr ${OPTIND-1} - 1` [ $# -lt 1 ] && usage # Search for a suitable "awk" implementation; prefer the fastest one : ${AWK:=`searchprog mawk || searchprog gawk || searchprog nawk || echo awk`} for word do # Get the query result page # Note that the resulting page may contain very large lines # (> 8K) some standard "awk" (i.e. Solaris 2.5) cannot # handle. GNU awk ("gawk") does not have these restrictions. # If you don't have "gawk", you could try to limit the line # size using other tools before the data reaches "awk". encoded=`echo "$word" | urlencode` $GETURL $GETURLFLAGS "$CGIURL$encoded" | # get page data { grep . || msg "WARNING: could not retrieve page: $CGIURL$encoded" } | #umbruch | # fold long lines $AWK '/ENGLIS[C]*H/, /\/[tT][aA][bB][lL][eE]/' | # start of result table sed 's/ / /g' | tr -d ' ' | dumphtmltbl -f | # ...and extract table data tail +4 | # skip column heading nicecol -i '\t' | egrep . || msg "no translation for \"$word\"" done